-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweather.py
executable file
·59 lines (46 loc) · 1.72 KB
/
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
#!/usr/bin/env python3
import sys
import requests
import json
import os
def banner():
os.system('clear')
print("+---------------+")
print("| \'The Weather\' |")
print("| Author: " + "\u2141" + "lyph |")
print("+---------------+")
def main():
url = "https://community-open-weather-map.p.rapidapi.com/forecast"
headers = { 'X-RapidAPI-Host':'community-open-weather-map.p.rapidapi.com',
'X-RapidAPI-Key': '09bb8fd4a7msh36e40cae1db3fb4p11e9b6jsnbdde1dc164f2'
}
params = { "q":"sydney,036","units":"metric","lang":"en","id":"Sydney" }
r = requests.get(url, headers=headers, params=params)
json_object = json.loads(r.text)
list1 = (json_object)['list']
dictionary = list1[0]
dt = (dictionary['dt']) # type int
main = (dictionary['main']) # type dictionary
weather = (dictionary['weather']) # type list
clouds = (dictionary['clouds']) # type dictionary
wind = (dictionary['wind']) # type dictionary
sys = (dictionary['sys']) # type dictionary
dt_txt = (dictionary['dt_txt']) # type string
city = (json_object['city']['name'])
print ("+---------------+")
print (f"| City: {city}\t|" )
print ("+---------------+")
print ("+------------------------------------+")
print ("|\t\t\t\t |")
print ("| Details\t\t\t |")
print ("|\t\t\t\t |")
for k,v in main.items():
print (f"| {k}: \t{v}\t\t |")
for i in weather:
print (f"| Description:\t{i['main']}\t\t |")
print (f"|\t\t{i['description']} |")
print ("|\t\t\t\t |")
print ("+------------------------------------+")
if (__name__ == '__main__'):
banner()
main()