-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathget_weather.py
64 lines (44 loc) · 1.3 KB
/
get_weather.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
import requests
import json
api_key = 'YOUR_API_KEY'
base_url = "http://api.openweathermap.org/data/2.5/weather?"
city_name = "Stockholm"
complete_url = base_url + "appid=" + api_key + "&q=" + city_name + "&units=metric"
response = requests.get(complete_url)
x = response.json()
#GLOBALS
y = x["main"]
print(y)
current_temp = y["temp"]
max_temp = round((y["temp_max"]))
min_temp = round(y["temp_min"])
humidity = y["humidity"]
pressure = y["pressure"]
feels = y["feels_like"]
previous_temp = 23
def temp_difference():
global previous_temp
#Getting percentage of difference between old and new temp
change_percent = ((float(current_temp) - max_temp) / max_temp) * 100
#To int instead of float
change_percent = int(change_percent)
print(change_percent)
if previous_temp > current_temp:
return str(change_percent)
# if its an increase we add a + symbol.
if previous_temp < current_temp:
return "+" + str(change_percent)
if change_percent == 0:
return "0"
def get_temp():
return(str(current_temp)+" °C")
def get_temp_min():
return(str(min_temp)+" °C")
def get_temp_max():
return(str(max_temp)+" °C")
def get_humidity():
return(str(humidity))
def get_pressure():
return(str(pressure))
def get_feel():
return(str(feels)+"°C")