Python Forum
Help with storing temp data for each day then recording min/max in app.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with storing temp data for each day then recording min/max in app.
#1
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.
Larz60+ write Sep-10-2021, 08:55 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please don't use images to post code. Use bbcode instead.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
getWeather function never used.
city and state not defined for line 8
Reply
#3
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
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Recording a Conversation puvuz 0 410 Jan-31-2025, 02:00 AM
Last Post: puvuz
  LLM data I/O - for storing notes Alkanet 0 318 Dec-19-2024, 09:08 AM
Last Post: Alkanet
  Storing data in readable place user_404_lost_and_found 4 1,375 Jul-22-2024, 06:14 AM
Last Post: Pedroski55
  Deleting Windows temp folder Raysz 7 2,894 Apr-02-2024, 12:36 PM
Last Post: Raysz
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 2,317 Feb-24-2023, 06:14 PM
Last Post: deanhystad
Smile How we can prevent screen recording murad_ali 3 3,547 Jul-29-2022, 10:29 AM
Last Post: DeaD_EyE
  How to decrease latency while recording streaming video. unicorn2019 0 1,692 Nov-15-2021, 02:12 PM
Last Post: unicorn2019
  pyspark creating temp files in /tmp folder aliyesami 1 7,047 Oct-16-2021, 05:15 PM
Last Post: aliyesami
  Split recording with Picamera EvanS1 0 2,572 Jun-19-2021, 12:26 PM
Last Post: EvanS1
  How to save Matplot chart to temp file? Morkus 2 5,797 Jun-12-2021, 10:52 AM
Last Post: Morkus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020