-
Notifications
You must be signed in to change notification settings - Fork 221
/
insert.py
116 lines (89 loc) · 2.67 KB
/
insert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# python insert.py {domain}
import os
import sys
import psycopg2
import base64
import telebot
bot = telebot.TeleBot(os.environ['API_KEY'])
chat_id = os.environ['CHAT_ID']
last = False
url = sys.argv[1]
try:
temp = sys.argv[2]
last = True
except:
pass
conn = psycopg2.connect(
host="db",
database="test_db",
user="test_user",
password="test_password"
)
cur = conn.cursor()
#checking if any previous entry in the database to avoid duplicates
cur.execute("select * from output;")
t = cur.fetchall()
doms = []
for i in t:
doms.append(i[0])
if url in doms:
try:
f = open('results/{}-output.txt'.format(url), 'r')
res1 = f.read()
f.close()
f = open('results/{}-gau.txt'.format(url), 'r')
res2 = f.read()
f.close()
res1 = bytes(res1, 'utf-8')
final1 = base64.standard_b64encode(res1)
final1 = final1.decode('utf-8')
res2 = bytes(res2, 'utf-8')
final2 = base64.standard_b64encode(res2)
final2 = final2.decode('utf-8')
cur.execute(f"update output set result = '{final1}' where domain = '{url}';")
conn.commit()
cur.execute(f"update output set gau = '{final2}' where domain = '{url}';")
conn.commit()
except:
f = open('results/{}-output.txt'.format(url), 'r')
res1 = f.read()
f.close()
res1 = bytes(res1, 'utf-8')
final1 = base64.standard_b64encode(res1)
final1 = final1.decode('utf-8')
cur.execute(f"update output set result = '{final1}' where domain = '{url}';")
conn.commit()
cur.execute(f"update output set gau = 'The Gathered URLs not run yet !' where domain = '{url}';")
conn.commit()
else:
try:
#read from output.txt and dump in database
f = open('results/{}-output.txt'.format(url), 'r')
res1 = f.read()
f.close()
f = open('results/{}-gau.txt'.format(url), 'r')
res2 = f.read()
f.close()
res1 = bytes(res1, 'utf-8')
final1 = base64.standard_b64encode(res1)
final1 = final1.decode('utf-8')
res2 = bytes(res2, 'utf-8')
final2 = base64.standard_b64encode(res2)
final2 = final2.decode('utf-8')
cur.execute(f"insert into output values ('{url}', '{final1}', '{final2}');")
conn.commit()
except:
#read from output.txt and dump in database
f = open('results/{}-output.txt'.format(url), 'r')
res1 = f.read()
f.close()
res1 = bytes(res1, 'utf-8')
final1 = base64.standard_b64encode(res1)
final1 = final1.decode('utf-8')
cur.execute(f"insert into output values ('{url}', '{final1}', 'The Gathered URLs not run yet !');")
conn.commit()
conn.commit()
if last:
bot.send_message(chat_id, f"scanned results of {url} is saved in db")
cur.close()
conn.close()