Repository navigation
Expand file tree
/
Copy pathweather.py
More file actions
47 lines (36 loc) · 1.64 KB
/
Copy pathweather.py
File metadata and controls
47 lines (36 loc) · 1.64 KB
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
import time
import requests
from pprint import pprint
from time import sleep
city = 'Huttwil,ch' #input('Enter your City: ')
API_KEY = 'your OpenWeather API key'
url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=metric&mode=json&APPID={}'.format(city, API_KEY)
res = requests.get(url)
data = res.json()
Sunrise_in_houers = int(time.strftime("%H", time.localtime(data['sys']['sunrise']))) * 60
Sunrise_in_minutes = int(time.strftime("%M", time.localtime(data['sys']['sunrise'])))
Sunrise_in_a_rounded_minute = round((float(time.strftime("%S", time.localtime(data['sys']['sunrise'])))) / 60)
Sunrise_in_minutes_of_the_day = int(Sunrise_in_houers + Sunrise_in_minutes + Sunrise_in_a_rounded_minute)
Sunset_in_houers = int(time.strftime("%I", time.localtime(data['sys']['sunset']))) * 60 #%I or %H for 12 or 24 houer format
Sunset_in_minutes = int(time.strftime("%M", time.localtime(data['sys']['sunset'])))
Sunset_in_a_rounded_minute = round((float(time.strftime("%S", time.localtime(data['sys']['sunset'])))) / 60)
Sunset_in_minutes_of_the_day = int(Sunset_in_houers + Sunset_in_minutes + Sunset_in_a_rounded_minute)
sunset = time.strftime(" %H:%M:%S", time.localtime(data['sys']['sunset']))
clouds = data['clouds']['all']
temp = data['main']['temp']
rain = data['sys']
humidity = data['main']['humidity']
##print(Sunrise_in_minutes_of_the_day)
##print(Sunset_in_minutes_of_the_day)
##print(clouds)
##print('Temperatur: {}'.format(temp))
##pprint(data)
def API_HUMIDITY():
API_HUMIDITY = humidity
sleep(1)
return API_HUMIDITY
def API_TEMPERATURE():
API_TEMPERATURE = temp
sleep(1)
return API_TEMPERATURE
#print(API_HUMIDITY())