-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.py
59 lines (48 loc) · 1.47 KB
/
script.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
import json
import time
import threading
from urllib import request
from progress.bar import Bar
from datetime import datetime
filename = "lista_urls.txt"
def create_json(nomeJson, logger):
with open(nomeJson, 'w') as fp:
json.dump(logger, fp)
def execute_url_list(casa, logger, nomeJson):
try:
start = time.time()
result = request.urlopen(casa)
end = time.time()
if result.status != 200:
log = {'url':casa,'status':result.status,'tempo':end-start}
logger['erros'].append(log)
except Exception as e:
end = time.time()
log = {'url':casa, 'status':str(e),'tempo':end-start}
logger['erros'].append(log)
return (logger)
create_json(nomeJson, logger)
def threads(casas, logger, nomeJson):
bar = Bar('Loading', fill='@', suffix='%(percent)d%%',max= 1000)
threads = [threading.Thread(target=execute_url_list,
args=(casa,logger, nomeJson, )) for casa in casas]
print("Start")
for thread in threads:
thread.start()
bar.next()
for thread in threads:
thread.join()
bar.goto(1000)
def main():
while(True):
logger = {'erros':[]}
nomeJson = "{}.json".format(str(datetime.now()))
with open(filename) as casas:
casas = list(casas)
casas = casas[1:]
threads(casas, logger, nomeJson)
print()
print("Done!")
time.sleep(600)
if __name__ == '__main__':
main()