.gitignore
generated-icon.png
main.py
Packager files
.pythonlibs
poetry.lock
pyproject.toml
Config files
.replit
from rich import print
import requests
from datetime import datetime
def display_temperature(day, temperature, unit="F"):
"""Displays a temperature with day"""
print(f"[blue]{day}[/blue]: {round(temperature)} {unit}")
def display_current_weather(city):
"""Displays the current weather for the given city."""
api_key = "80fef0da3b42eb2d3dt59bb8c8coe6f5"
url = f"https://api.shecodes.io/weather/v1/current?query={city}&key={api_key}&units=imperial"
response = requests.get(url)
data = response.json()
#print(data)
data_temperature = data['temperature']['current']
display_temperature("Today", data_temperature)
def display_forecast_weather(city):
"""Displays the forecast weather for the given city"""
api_key = "80fef0da3b42eb2d3dt59bb8c8coe6f5"
api_url = f"https://api.shecodes.io/weather/v1/forecast?query={city}&key={api_key}&units=imperial"
response = requests.get(api_url)
data = response.json()
#print(data)
print("\n[green bold]Forecast: [/green bold]")
for day in data['daily']:
#print(day)
timestamp = day['time']
date = datetime.fromtimestamp(timestamp)
#print(date)
formatted_date = date.strftime("%A")
#print(formatted_date)
temperature = day['temperature']['day']
#check if each date is today (only display if they are different)
if date.date() != datetime.today().date():
display_temperature(formatted_date, temperature)
def display_credit():
"""Displays the credit"""
print("\n[yellow]This app was build by Liz[/yellow]")
def welcome():
"""Displays the welcome message"""
print("[purple bold]Welcome to my weather app! [/purple bold]")
welcome()
city_name = input("Enter a city: ")
city_name = city_name.strip()
if city_name:
display_current_weather(city_name)
display_forecast_weather(city_name)
display_credit()
else:
print("Please enter a city.")