-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (23 loc) · 903 Bytes
/
app.py
File metadata and controls
29 lines (23 loc) · 903 Bytes
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
import requests
import json
url = 'https://guilhermeonrails.github.io/api-restaurantes/restaurantes.json'
response = requests.get(url)
print(response)
if response.status_code == 200:
dados_json = response.json()
dados_restaurante = {}
for item in dados_json:
nome_do_restaurante = item['Company']
if nome_do_restaurante not in dados_restaurante:
dados_restaurante[nome_do_restaurante] = []
dados_restaurante[nome_do_restaurante].append({
"item": item['Item'],
"price": item['price'],
"description": item['description']
})
else:
print (f'O erro foi {response.status_code}')
for nome_do_restaurante, dados in dados_restaurante.items():
nome_do_arquivo = f'{nome_do_restaurante}.json'
with open(nome_do_arquivo, 'w') as arquivo_restaurante:
json.dump(dados, arquivo_restaurante, indent=4)