Skip to content
    PythonWeatherProject@sarahwiens88
    .gitignore
    main.py
    Packager files
    pyproject.toml
    uv.lock
    Config files
    .replit
    import requests, pytz
    from rich import print
    from datetime import datetime
    from timezonefinder import TimezoneFinder

    def display_current_weather(city):
    """Shows the current temperature in the user-provided city"""
    api_key = "7f314bd46t448eb65o54002ab9dadc03"
    api_url = f"https://api.shecodes.io/weather/v1/current?query={city}&key={api_key}"
    response = requests.get(api_url)
    current_weather = response.json()
    current_temperature = round(current_weather['temperature']['current'])
    print(f"\n[blue]Today:[/blue] [white]{current_temperature}°C[/white]")


    def display_weather_forecast(city):
    """Pulls the weather forecast data for the user-provided city and then displays only the future temperatures"""
    api_key = "7f314bd46t448eb65o54002ab9dadc03"
    forecast_url = f"https://api.shecodes.io/weather/v1/forecast?query={city}&key={api_key}"
    response_forecast = requests.get(forecast_url)
    forecast_weather = response_forecast.json()
    longitude=forecast_weather['coordinates']['longitude']
    latitude=forecast_weather['coordinates']['latitude']
    timezone_str=TimezoneFinder().timezone_at(lng=longitude, lat=latitude)
    timezone = pytz.timezone(timezone_str)
    current_weekday = datetime.now(timezone).strftime("%A")
    print(f"\n[bold green]Forecast:[/bold green]")
    for daily_forecast in forecast_weather['daily']:
    forecast_temperature=round(daily_forecast['temperature']['day'])
    weekday=datetime.fromtimestamp(daily_forecast['time']).strftime("%A")
    if weekday != current_weekday:
    print(f"[blue]{weekday}[/blue]: [white]{forecast_temperature}°C[/white]")

    def display_missing_city_error():
    """Shows an error message if the user doesn't provide a city"""
    print("\n[bold red]*** Please try again with a city ***[/bold red]")

    print("[bold purple]Welcome to my weather app[/bold purple]\n")
    city = input("Enter a city: ").strip()

    if city:
    display_current_weather(city)
    display_weather_forecast(city)
    print("\n[yellow]This app was built by Sarah Wiens[/yellow]")
    else:
    display_missing_city_error()