File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments