-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests_sos_rs.py
56 lines (46 loc) · 1.47 KB
/
requests_sos_rs.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
from constants import *
import requests
def fetch_supply_categories_data():
url = f"{API_URL}/supply-categories"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data['data']
else:
print("Falha na requisição:", response.status_code)
return None
def fetch_shelter_data():
perPage = 100
page = 1
all_data = []
while True:
url = f"{API_URL}/shelters?page={page}&perPage={perPage}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
if len(data['data']['results']) == 0:
break # Sai do loop se o array de resultados estiver vazio
all_data.extend(data['data']['results'])
page += 1
else:
print("Falha na requisição:", response.status_code)
break
return all_data
def fetch_shelter_data_by_id(id):
url = f"{API_URL}/shelters/{id}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data['data']
else:
print("Falha na requisição:", response.status_code)
return None
def fetch_supplies_data():
url = f"{API_URL}/supplies"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data['data']
else:
print("Falha na requisição:", response.status_code)
return None