-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvt_api_call.py
48 lines (33 loc) · 1.27 KB
/
vt_api_call.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
import json
import requests
from vt_api_json_print import *
from vt_api_state import *
def call_vt_api(url, api_key, program_files_path):
state = load_state(program_files_path)
call_state(state, program_files_path)
api_json_response_path = os.path.join(program_files_path, "vt_response.json")
headers = {
"x-apikey": api_key,
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
dados = response.json()
with open(api_json_response_path, 'w') as file:
json.dump(dados, file, indent=4)
print_json(api_json_response_path)
else:
print(f"Error code: {response.status_code}")
dados = response.json()
with open(api_json_response_path, 'w') as file:
json.dump(dados, file, indent=4)
with open(api_json_response_path, 'r', encoding='utf8') as file:
jsonString = file.read()
if not jsonString:
print("Arquivo vazio")
exit()
data = json.loads(jsonString)
print(data['error']['message'])
print("\nJSON file saved to: {}".format(api_json_response_path))
#print(state)
save_state(state, program_files_path)