I showed you a working function in your last Thread
Now you mess it up with serval errors one mention bye ibreeden and call
All the globals values should not just get be used in function if there not are in function parameter.
As mention in last post do small teste as your function now it's not working at all,
then you stop and fix function before adding ConfigParser and GUI.
To show a example with ConfigParser using my code from last Thread.
As api_key is personal to you should not need to type in every time,have in api_key in the
key.ini:
Now you mess it up with serval errors one mention bye ibreeden and call
json
should be json_data
.All the globals values should not just get be used in function if there not are in function parameter.
As mention in last post do small teste as your function now it's not working at all,
then you stop and fix function before adding ConfigParser and GUI.
To show a example with ConfigParser using my code from last Thread.
As api_key is personal to you should not need to type in every time,have in api_key in the
.ini
file.key.ini:
[key] api_key = xxxxxxxxxxxxx
import requests from configparser import ConfigParser def get_weather(city, api_key): api = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}" json_data = requests.get(api).json() return json_data def get_api_key(): config = ConfigParser() config.read('key.ini') api_key = config['key']['api_key'] return api_key if __name__ == '__main__': city = 'Winnsboro,Louisiana' weather = get_weather(city, get_api_key()) print(weather['name']) print(weather['main']['temp']) print(weather[ 'weather'][0]['description'])
Output:Winnsboro
295.99
overcast clouds