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
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,180 Feb-24-2023, 06:14 PM
Last Post: deanhystad
Smile How we can prevent screen recording murad_ali 3 1,761 Jul-29-2022, 10:29 AM
Last Post: DeaD_EyE
  How to decrease latency while recording streaming video. unicorn2019 0 1,232 Nov-15-2021, 02:12 PM
Last Post: unicorn2019
  pyspark creating temp files in /tmp folder aliyesami 1 4,822 Oct-16-2021, 05:15 PM
Last Post: aliyesami
  Split recording with Picamera EvanS1 0 1,881 Jun-19-2021, 12:26 PM
Last Post: EvanS1
  How to save Matplot chart to temp file? Morkus 2 4,436 Jun-12-2021, 10:52 AM
Last Post: Morkus
  Problem with storing data in SQLAlchemy db marcello86 1 2,582 Aug-31-2020, 09:44 PM
Last Post: Larz60+
  Using pyaudio to stop recording under certain sound threshold Twanski94 2 6,302 Jun-13-2020, 11:35 AM
Last Post: Twanski94
  recording a translation table into a file arbiel 0 1,421 Mar-31-2020, 02:33 PM
Last Post: arbiel
  Recording audio to file until no dialogue. diffLocks16 1 2,238 Aug-14-2019, 04:37 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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