Skip to content

Commit

Permalink
Create get_wheater.py
Browse files Browse the repository at this point in the history
  • Loading branch information
arainho committed May 31, 2023
1 parent 49cb55d commit 16997b2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/get_wheater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

# importing all is less advised
#import configparser
#import sys

import requests
from sys import argv
from configparser import ConfigParser
from json import dumps

def get_api_key():
config = ConfigParser()
config.read('config.ini')
return config['openweathermap']['api_key']

def get_base_url():
config = ConfigParser()
config.read('config.ini')
return config['openweathermap']['base_url']

def get_weather(base_url, api_key, city):
url = "{base_url}/weather?q={location}&units=metric&appid={key}".format(base_url=base_url, location=city, key=api_key)
r = requests.get(url)
return r.json()

def main():
if len(argv) != 2:
exit("Usage: {} CITY".format(argv[0]))
city = argv[1]

api_key = get_api_key()
base_url = get_base_url()
weather = get_weather(base_url, api_key, city)

average_temp = input("Enter average temperature:")

#print(weather['main']['temp'])
print("{} - currentTemp is:".format(average_temp))
print(eval("average_temp-weather['main']['temp']"))

if __name__ == '__main__':
main()

0 comments on commit 16997b2

Please sign in to comment.