ISCOUTB / AG-WeatherWhisper

GNU Affero General Public License v3.0
0 stars 2 forks source link

Implementar la función para obtener los datos meteorológicos actuales (temperatura, humedad, etc.) de una API de clima. #3

Closed VictorMtMwr closed 1 day ago

VictorMtMwr commented 4 days ago

def GetData(): api_key = "ud4J9RTtncJIFktrHWfpN59y3VLVVfhb" location = str(input("Enter location: "))

    url = f"https://api.tomorrow.io/v4/weather/realtime?location={location}&apikey={api_key}"

    headers = {"accept": "application/json"}

    response = requests.get(url, headers=headers)

    def print_dict(data, indent=0):
        for key, value in data.items():
            print("  " * indent + f"{key}:")
            if isinstance(value, dict):
                print_dict(value, indent + 1)
            else:
                print("  " * (indent + 1) + f"{value}")

    if response.status_code == 200:
        data = response.json()
        print_dict(data)
    else:
        print("Error:", response.status_code)

GetData()