-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (83 loc) · 2.33 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
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
# map.json time sleep 5 s
# reduce.json time sleep 10800
import json
import os
import requests
from datetime import datetime, timedelta
from time import sleep
re = requests
# Url de requisição
url = 'https://hcomunicaapi.cnj.jus.br/api/v1/comunicacao'
conttrole_time = datetime.now()
cont = 1
# time i segundos
req_ps = 2
# time em horas
reduce_rt = 10
def dormir(sec=1):
for x in range(1, sec):
print("\n", end='')
print(f'estou no segundo: ', x, end='')
sleep(1)
def reduce():
with open(f'map.txt', 'r') as arq:
filename=arq.name
list_erros=[]
while True:
read=arq.readline()
if read == '':
break
print(read)
read = json.loads(read)
if read['status_code'] != 200:
list_erros.append(read['uuid'])
if len(list_erros) > 0:
status_ok = False
else:
status_ok = True
line={'filename' : arq.name,
'status_ok' : status_ok,
'list_erros' : list_erros
}
with open('reduce.txt', 'a') as arq:
line = json.dumps(line)
print(line)
arq.write(line)
pass
def map():
re = requests
# Url de requisição
url = 'https://hcomunicaapi.cnj.jus.br/api/v1/comunicacao'
conttrole_time = datetime.now()
cont = 1
# time i segundos
req_ps = 2
# time em horas
reduce_rt = 30
while True:
response = re.get(url=url)
with open(f'map.txt', 'a') as arq:
resut = json.loads(response.text)
if f'{response.status_code}'[-1] != "0":
sud_status = response.status_code
else:
sub_status = 0
line = {
'uuid': cont,
'time': str(datetime.now()),
'status_code': response.status_code,
'sub_statuscode': sub_status,
'headers' : str(response.headers),
'content': response.text
}
line = json.dumps(line)
arq.write(line)
arq.write('\n')
if conttrole_time + timedelta(seconds = reduce_rt) <= datetime.now():
reduce()
conttrole_time=datetime.now()
cont += 1
dormir(req_ps)
if __name__ == '__main__':
# map()
reduce()