Python Forum
Help with storing temp data for each day then recording min/max in app. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with storing temp data for each day then recording min/max in app. (/thread-34873.html)



Help with storing temp data for each day then recording min/max in app. - trthskr4 - Sep-10-2021

Hello, I just started trying to learn programming 3 days ago. I'm following online courses and researching about 4-6 hours a day. I'm one of those who has to learn by doing and making mistakes so I started making an app that will log weather temps current, min/max each day as well as barometric pressure and humidity because I have Meniere's Disease and this affects it greatly. Would also help many others if they used it. I have just started and I don't know how to store the data as it comes in from the weather api and then record it in the app. Any help would be appreciated.

import tkinter as tk
import requests
import time

def getWeather():
    location = textfield.get()
    #https://api.openweathermap.org/data/2.5/weather?q=Winnsboro,Louisiana&appid=xxxxxxxxxxx
api = "api.openweathermap.org/data/2.5/weather?q=" + city + state + "&appid=xxxxxxxxxxx"
json_data = requests.get(api).json()
condition = json_data['weather'][0]['main']
temp = int(json_data['main']['temp'])
max_temp = int(json_data['main']['temp_max'])
min_temp = int(json_data['main']['temp_min'])

press = int(json_data['main']['pressure'])
#max_press = int(json_data['main']['pressure_max'])
#min_press = int(json_data['main']['pressure_min'])

humidity = int(json_data['main']['humidity'])


canvas = tk.Tk()
canvas.geometry("960x600")
canvas.title("Meniers App")

f = ("poppins", 20,)
t = ("poppins", 25, "bold")

textfield = tk.Entry(canvas, font = t)
textfield.pack(pady = 25)
textfield.focus()
Thanks in advance.


RE: Help with storing temp data for each day then recording min/max in app. - Larz60+ - Sep-10-2021

getWeather function never used.
city and state not defined for line 8


RE: Help with storing temp data for each day then recording min/max in app. - snippsat - Sep-10-2021

As mention there are serval basic problem with code.
Here a fix for the function,do small test and don't just mix GUI before the basic stuff work.
Have removed your API key as should not post that as it's private to you.
import requests

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

if __name__ == '__main__':
    api_key = 'xxxxxxxxx'
    city = 'Winnsboro,Louisiana'
    weather = get_weather(city, api_key)
    print(weather['name'])
    print(weather['main']['temp'])
    print(weather['weather'][0]['description'])
Output:
Winnsboro 288.64 clear sky



RE: Help with storing temp data for each day then recording min/max in app. - trthskr4 - Sep-10-2021

(Sep-10-2021, 09:12 AM)Larz60+ Wrote: getWeather function never used.
city and state not defined for line 8

Thank you, didn't even think about the api code. LOL was already braindead trying to figure it out.