-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
58 lines (41 loc) · 1.3 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
import requests as rq
from datetime import datetime
import pandas as pd
import os
class GetDays():
# Make load to csv
def load(self, df_content: pd.DataFrame) -> None:
try:
if os.path.isfile("./data.csv"):
os.remove("./data.csv")
print(df_content)
df_content.to_csv("data.csv")
except Exception as e:
print("Error loading the data" + str(e))
# Make transform to dataframe
def transform(self, content: list) -> pd.DataFrame:
try:
df_c = pd.DataFrame(content)
except Exception as e:
print("Error transforming the data" + str(e))
return df_c
# Make extraction from url
def extract(self) -> list:
try:
response = rq.get(self.url)
content: list = list(response.json())
except Exception as e:
print("Error extracting data" + str(e))
return []
return list(content)
def __init__(self,
url: str="https://nolaborables.com.ar/api/v2/feriados/" +
str(datetime.now().year)) -> None:
self.url: str = url
def main():
g_d = GetDays()
content = g_d.extract()
df_c = g_d.transform(content)
g_d.load(df_c)
if __name__ == "__main__":
main()