Sep-12-2021, 02:48 PM
I'm stumped again. Been trying different ways of getting this to work and its solution is evading me. LOL
Just learning and am running Python 3.9.7
My next hurdle is to get the api key from it once and store in config.ini permanently and then get the user interface window up and running.
Just learning and am running Python 3.9.7
My next hurdle is to get the api key from it once and store in config.ini permanently and then get the user interface window up and running.
from tkinter import * from configparser import ConfigParser import requests name = input("Name?: ") age = input("Age?: ") weightLBS = input("Weight in lbs?: ") diagnosed = input("Have you been diagnosed with MD by doctor?: ") api_key = input("API key? ") #Weather API json and data pull url = "http//api.openweathermap.org/data/2.5/weather?q={},{}&appid={}" city = input("City where you are?: ") state = input("State where you are? ") api_key = config_file = 'config.ini' config = ConfigParser() config.read('config_file') #api_key = input(api_key) #(config.ini[api_key][key]) def get_weather(city, state, api_key): result = requests.get_weather(url.format(city, state, api_key)) if result: print(result.json_data) json_data = result.json() city = json['name'] temp_kelvin = json['main']['temp'] temp_min_kelvin= json['main']['temp_min'] temp_max_kelvin = json['main']['temp_max'] temp_fahrenheit = (temp_kelvin - 273.15) * 9 / 5 + 32 temp_min_fahrenheit = (temp_min_kelvin - 273.15) * 9 / 5 + 32 temp_max_fahrenheit = (temp_max_kelvin - 273.15) * 9 / 5 + 32 humidity = json['main']['humidity'] pressure = json['main']['pressure' * 0.0295301] condition = json_data['weather'][0]['main'] #max_press = int(json_data['main']['pressure_max']) #min_press = int(json_data['main']['pressure_min']) final = (name, city, state, age, weight, diagnosed, temp_fahrenheit, temp_min_fahrenheit, temp_max_fahrenheit, humidity, pressure, condition) return final print(get_weather(city, state, api_key))