.gitignore
main.py
Packager files
.pythonlibs
poetry.lock
pyproject.toml
Config files
.replit
import requests
from rich import print
from datetime import datetime
def greeting():
"""display greeting"""
print("[purple bold]Welcome to my weather app[/purple bold]")
greeting()
user_city = input("Enter your city: ")
user_city = user_city.strip()
def day_temperature(day, temperature, unit='C'):
"""display temperature and day"""
print(f"[blue]{day}[/blue]: {round(temperature)}º{unit}")
def user_city_current_temperature(city):
"""current temperature of the city"""
api_key="a0ba51c5f21a3d78e240d23c5oet7bf2"
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_weather_city = current_weather['city']
current_temperature_city=current_weather['temperature']['current']
day_temperature("Today", round(current_temperature_city))
def user_city_forecast_weather(user_city):
"""Display weather forecast of a city"""
api_key = "a0ba51c5f21a3d78e240d23c5oet7bf2"
api_url = f"https://api.shecodes.io/weather/v1/forecast?query={user_city}&key={api_key}"
response = requests.get(api_url)
forecast_weather = response.json()
print("\n[green bold]Forecast:[/green bold]")
for day in forecast_weather['daily']:
timestamp = day['time']
date = datetime.fromtimestamp(timestamp)
formatted_day = date.strftime("%A")
temperature = day['temperature']['day']
if date.date() != datetime.today().date():
day_temperature(formatted_day, round(temperature))
def credit():
"""Display credits"""
print("\n[cyan2]This app was built by Camila Velez[/cyan2]")
if user_city:
user_city_current_temperature(user_city)
user_city_forecast_weather(user_city)
credit()
else:
print("Please try again with a city")