-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_server.py
35 lines (29 loc) · 1.08 KB
/
test_server.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
import requests
BASE_URL="http://127.0.0.1:5000"
def test_create():
resp = requests.post(BASE_URL + '/send-recommendations')
print(resp.json())
def test_weather():
weather = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/goias?unitGroup=metric&key=VJA6USVNWLGA4Z3F2CTMHHVQW&contentType=json'
resp = requests.get(weather).json()
# for day in resp['days']:
# print(day['datetime'])
# print(resp['days'][0])
# get tempmax, tempmin, humidity, precip, precipprob, windspeed
daily_weather = {}
for day in resp['days']:
daily_weather[day['datetime']] = {
'tempmax': day['tempmax'],
'tempmin': day['tempmin'],
'humidity': day['humidity'],
'precip': day['precip'],
'precipprob': day['precipprob'],
'windspeed': day['windspeed']
}
# Calculate the total rain for the 2 weeks
total_rain = 0
for day in daily_weather:
total_rain += daily_weather[day]['precip']
print(total_rain)
if __name__ == '__main__':
test_weather()