Skip to content
    JodieRBasicsProject@jodieryan
    .gitignore
    main.py
    Packager files
    poetry.lock
    pyproject.toml
    Config files
    .replit
    import requests
    from datetime import datetime
    from rich import print



    def display_temperature(day, temperature, unit='C'):
    """Displays temperature with the day"""
    print(f"[blue]{day}[/blue]: {round(temperature)}°{unit}")



    def display_current_weather(city_name):
    """Display the current weather for the chosen city"""
    api_key = "0368o0da78c5ff86f8ab924f69t6aa0b"
    api_current_url = f"https://api.shecodes.io/weather/v1/current?query={city_name}&key={api_key}"

    response = requests.get(api_current_url)
    current_weather_data = response.json()
    current_weather_city=current_weather_data['city']
    current_weather_temperature=current_weather_data['temperature']['current']

    display_temperature("\n\nToday", round(current_weather_temperature))





    def display_forecast_weather(city_name):
    """Displays the forecast weather for the chosen city"""
    api_key="0368o0da78c5ff86f8ab924f69t6aa0b"
    api_forecast_url=f"https://api.shecodes.io/weather/v1/forecast?query={city_name}&key={api_key}"
    response=requests.get(api_forecast_url)
    forecast_weather_data=response.json()
    print("\n[yellow bold]Forecast: [/yellow bold]")
    for day in forecast_weather_data['daily']:
    timestamp=day['time']
    date=datetime.fromtimestamp(timestamp)
    formatted_day=date.strftime("%A")
    forecast_temperature=day['temperature']['day']

    if date.date() != datetime.today().date():
    display_temperature(formatted_day, round(forecast_temperature))

    def credit():
    """Displays a credit message"""
    print("\n[purple]Weather App built by: [/purple] [pink]Jodie Ryan[/pink]\n")


    def welcome():
    """Displays a welcome message at the beginning"""
    print(f"[purple bold]Welcome to this amazing weather app![/purple bold]\n")



    welcome()
    city_name = input("Enter the city name: ")
    city_name =city_name.strip().title()


    if city_name:
    display_current_weather(city_name)
    display_forecast_weather(city_name)
    credit()
    else:
    print("Please try again with city")

    #Get the city from the user