-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
73 lines (39 loc) · 1.58 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Imports
import pandas as pd
import requests
import datetime
import schedule
def update_sheet():
"""
Input: None
Output: Updated Excel sheet
"""
url = "https://api.openweathermap.org/data/2.5/weather?q=New%20York&units=metric&appid={API_Key}"
json_response = requests.get(url).json()
variables_of_interest = [json_response['weather'][0]['main'],
json_response['main']['temp'],
json_response['main']['humidity']]
# Date/Time stamps
datetimestamp = datetime.datetime.now()
month = datetime.datetime.now().month
day = datetime.datetime.now().day
hour = datetime.datetime.now().hour
minute = datetime.datetime.now().minute
df = pd.DataFrame(variables_of_interest).transpose()
df['Date/Time stamp'] = datetimestamp
df['Month'] = month
df['Day'] = day
df['Hour'] = hour
df['Minute'] = minute
df.columns = ["Desc", "Temp (C)", "Humidity", "Date/Time stamp", "Month", "Day", "Hour", "Minute"]
# Read last version of data
last_version = pd.read_excel("API_demo_results.xlsx", index_col= 0)
# Concat
concat = pd.concat([last_version, df])
# Write back to Excel sheet
concat.to_excel("API_demo_results.xlsx")
return "job done at {}".format(datetime.datetime.now().strftime("%H : %M : %S"))
if __name__ == "__main__":
schedule.every(1).hour.do(update_sheet)
while True:
schedule.run_pending()