Python Forum
Getting "name 'get_weather' is not defined error and no json_data returned?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting "name 'get_weather' is not defined error and no json_data returned?
#1
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.

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))       
Reply


Messages In This Thread
Getting "name 'get_weather' is not defined error and no json_data returned? - by trthskr4 - Sep-12-2021, 02:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access values returned from inquirer cspower 6 822 Dec-26-2023, 09:34 PM
Last Post: cspower
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 597 Nov-23-2023, 02:53 PM
Last Post: rob101
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,143 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 2,367 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  SQLAlchemy Object Missing when Null is returned Personne 1 1,752 Feb-19-2022, 02:50 AM
Last Post: Larz60+
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 3,018 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,415 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 2,191 Dec-14-2020, 05:45 PM
Last Post: karabakh
  name error "name"is not defined MaartenRo 1 3,446 Jul-28-2020, 02:39 AM
Last Post: bowlofred
  Name Error: name 'Stockton' is not defined Pinokchu 3 2,295 Jun-13-2020, 02:48 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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