-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
85 lines (73 loc) · 2.64 KB
/
test.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
import requests
import json
import pymongo
import bitly_api
import time
import traceback
count = 0
def setup():
bitly_access_token, google_access_token, wot_access_token = getKeys()
long_url = 'ianfette.org'
URL = 'http://api.mywot.com/0.4/public_link_json2?hosts={long_url}/&key={key}'
URL = URL.format(key=wot_access_token, long_url=long_url)
response = requests.get(URL)
print(response.text)
label(google_access_token, long_url)
#bitly_connection = bitly_api.Connection(access_token = bitly_access_token)
#mongoclient = pymongo.MongoClient('127.0.0.1', 27017)
#db = mongoclient.tweets
#findLong(bitly_connection, db, google_access_token)
def findLong(bitly_connection, db, google_access_token):
cursor = db.bitly_urls.find(no_cursor_timeout = True)
record_count = 0
for record in cursor:
exception = True
while exception:
try:
long_url = bitly_connection.expand(shortUrl=record["shortened_url"])[0]['long_url']
print(long_url)
label(google_access_token, long_url)
record_count += 1
print(record_count)
exception = False
except Exception as err:
print(traceback.format_exc())
time.sleep(2)
pass
cursor.close()
def label(google_access_token, long_url):
URL = "https://safebrowsing.googleapis.com/v4/threatMatches:find?key={key}"
URL = URL.format(key=google_access_token)
request_body = {
"client": {
"clientId": "iiita",
"clientVersion": "1.0.0"
},
"threatInfo": {
"threatTypes": ["MALWARE", "SOCIAL_ENGINEERING", "UNWANTED_SOFTWARE", "POTENTIALLY_HARMFUL_APPLICATION", "THREAT_TYPE_UNSPECIFIED"],
"platformTypes": ["ANY_PLATFORM"],
"threatEntryTypes": ["URL"],
"threatEntries": [
{"url": long_url}
]
}
}
request_body = json.dumps(request_body)
response = requests.post(URL, data=request_body)
print(response.status_code)
print(response.text, end="")
if len(response.text) > 4:
global count
count += 1
print(count)
def getKeys():
inputFile = open('details.txt', 'r')
for i in range(4):
inputFile.readline()
bitly_access_token = inputFile.readline().strip().split(" ")[2]
google_access_token = inputFile.readline().strip().split(" ")[2]
wot_access_token = inputFile.readline().strip().split(" ")[2]
inputFile.close()
return (bitly_access_token, google_access_token, wot_access_token)
if __name__ == '__main__':
setup()