generated-icon.png
main.py
Packager files
.pythonlibs
poetry.lock
pyproject.toml
Config files
.replit
import requests
from rich import print
from datetime import datetime
def display_weather(city):
'''displays the weather for a given city'''
api_key = "dtacb933eof95d0694704c53009f47c5"
api_url = f"https://api.shecodes.io/weather/v1/current?query={city}&key={api_key}&units=metric"
response = requests.get(api_url)
weather = response.json()
temperature = weather["temperature"]["current"]
country = weather["country"]
print(f"It is currently {round(temperature)}°C in {city}, {country}.")
def display_forecast(city):
'''displays the forecast for a given city'''
api_key = "dtacb933eof95d0694704c53009f47c5"
api_url = f"https://api.shecodes.io/weather/v1/forecast?query={city}&key={api_key}&units=metric"
response = requests.get(api_url)
forecast = response.json()
# print(forecast)
for day in forecast["daily"]:
timestamp = day['time']
date = datetime.fromtimestamp(timestamp)
formatted_date = date.strftime("%A")
temperature = round(day['temperature']['day'])
if date.date() != datetime.today().date():
print(f"{formatted_date}: {temperature}°C")
def display_credit():
'''displays the credit'''
print("\nThis app was built by [magenta bold]Amy Bauer[/magenta bold] :)")
def display_welcome():
'''displays the welcome message'''
print(f"[magenta bold]Welcome to my weather app![/magenta bold]")
display_welcome()
city = input("Enter a city: ")
city = city.strip().capitalize()
if city:
display_weather(city)
print("\n[cyan bold underline]Forecast:[/cyan bold underline]")
display_forecast(city)
display_credit()
else:
print("Please enter a city.")