Skip to content

Commit 16997b2

Browse files
authored
Create get_wheater.py
1 parent 49cb55d commit 16997b2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

app/get_wheater.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
# importing all is less advised
4+
#import configparser
5+
#import sys
6+
7+
import requests
8+
from sys import argv
9+
from configparser import ConfigParser
10+
from json import dumps
11+
12+
def get_api_key():
13+
config = ConfigParser()
14+
config.read('config.ini')
15+
return config['openweathermap']['api_key']
16+
17+
def get_base_url():
18+
config = ConfigParser()
19+
config.read('config.ini')
20+
return config['openweathermap']['base_url']
21+
22+
def get_weather(base_url, api_key, city):
23+
url = "{base_url}/weather?q={location}&units=metric&appid={key}".format(base_url=base_url, location=city, key=api_key)
24+
r = requests.get(url)
25+
return r.json()
26+
27+
def main():
28+
if len(argv) != 2:
29+
exit("Usage: {} CITY".format(argv[0]))
30+
city = argv[1]
31+
32+
api_key = get_api_key()
33+
base_url = get_base_url()
34+
weather = get_weather(base_url, api_key, city)
35+
36+
average_temp = input("Enter average temperature:")
37+
38+
#print(weather['main']['temp'])
39+
print("{} - currentTemp is:".format(average_temp))
40+
print(eval("average_temp-weather['main']['temp']"))
41+
42+
if __name__ == '__main__':
43+
main()

0 commit comments

Comments
 (0)