forked from voltdatalab/crossfire
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fogocruzado_utils.py
43 lines (32 loc) · 1.04 KB
/
fogocruzado_utils.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
import logging
from functools import lru_cache
from pandas import DataFrame
from crossfire.client import Client
@lru_cache(maxsize=1)
def load_client():
return Client()
def to_dataframe(resp):
resp.encoding = "utf8"
return DataFrame(resp.json())
def extract_data_api(link):
"""
Extract data from occurrences in Fogo Cruzado's API
:param link: string
Request the API url with search parameters
:return: pandas.DataFrame
Result from the request API in pandas DataFrame format
"""
logging.info("Extracting data from Fogo Cruzado's API...")
client = load_client()
resp = client.get(url=link)
return to_dataframe(resp)
def extract_cities_api():
"""
Extract data from cities in Fogo Cruzado's API
:return: pandas.DataFrame
Result from the request API in pandas DataFrame format
"""
logging.info("Extracting data from Fogo Cruzado's API...")
client = load_client()
resp = client.get(url="https://api.fogocruzado.org.br/api/v1/cities")
return to_dataframe(resp)