-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (38 loc) · 1.07 KB
/
main.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
#!/usr/bin/python3
# coding: utf-8
import zipfile
import requests
import io
import process
DISTRIBUTE = True # Distribute tasks using redis
PURGE_DB = True # Reset DB on startup
STORE = process.STORE
out_path = process.out_path # For CSV store
start_file = "https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
q = None
if DISTRIBUTE:
from redis import Redis
from rq import Queue
q = Queue(connection=Redis())
zip_file = io.BytesIO(requests.get(start_file).content)
if PURGE_DB:
if STORE == "MONGODB":
import pymongo
mongo_client = pymongo.MongoClient()
mongo_db = mongo_client.tls_survey
mongo_db.sites.drop()
if STORE == "CSV":
self.out_file = open(out_path, "a")
out_file.write("site,http_version,answer_malformed,ssl_cipher\n")
out_file.close()
with zipfile.ZipFile(zip_file) as zipopen:
with zipopen.open("top-1m.csv") as f:
# CSV file opened
line = f.readline()
while line:
site = line.decode("utf-8").strip().split(",")[1]
if DISTRIBUTE:
result = q.enqueue(process.do_job, site)
else:
process.do_job(site)
line = f.readline()