.gitignore
index.ts
main.py
README.md
tsconfig.json
Packager files
.pythonlibs
bun.lockb
package.json
poetry.lock
pyproject.toml
Config files
.replit
import requests
from rich import print
from datetime import datetime
def display_temperature(day, temperature, units='C'):
print(f"[blue]{day}[/blue]:{round(temperature)}º{units}")
def display_current_weather(city):
api_key="4t7d303d7c1ea2908b8dfea4coaff2b4"
api_url=f"https://api.shecodes.io/weather/v1/current?query={city}&key={api_key}"
response=requests.get(api_url)
current_weather_data=response.json()
current_weather_city=current_weather_data['city']
current_weather_temperature=current_weather_data['temperature']['current']
display_temperature("Today",round(current_weather_temperature))
def display_forecast_weather(city_name):
api_key="4t7d303d7c1ea2908b8dfea4coaff2b4"
api_url=f"https://api.shecodes.io/weather/v1/forecast?query={city_name}&key={api_key}"
response=requests.get(api_url)
forecast_weather_data=response.json()
for day in forecast_weather_data['daily']:
timestamp=day['time']
date=datetime.fromtimestamp(timestamp)
date_formatted=date.strftime("%A")
temperature=day['temperature']['day']
if date.date() != datetime.today().date():
display_temperature(date_formatted, temperature)
def credit():
print("\n[violet bold] Made by Alex Nedelcut[violet bold]")
print("[purple bold underline]Welcome to the Weather App[/purple bold underline]")
print("")
city_name=input("Enter a city: ")
city_name=city_name.strip()
if city_name:
display_current_weather(city_name)
print("\n[green bold]Forecast[/green bold]:")
display_forecast_weather(city_name)
credit()
else:
print("Please enter a city")
# Exercise 1
#weather = {
# "city": "Lisbon",
# "country": "Portugal",
# "temperature": 17.94,
#"humidity": 77
#}
#city_name = weather['city']
#city_country = weather['country']
#city_temperature = weather['temperature']
#city_humidity = weather['humidity']
#fahrenheit = (city_temperature * 9 / 5) + 32
#print(
# f"It is {round(city_temperature)}ºC ({round(fahrenheit)}ºF) in {city_name}, {city_country} and the humidity level is {city_humidity}%."
#)
# Display the weather in Lisbon such as:
# It is 18ºC (64ºF) in Lisbon, Portugal, the humidity level is 77%.
#Exercise 2
#forecast = {
# "city": "Lisbon",
# "country": "Portugal",
# "daily": [17.76, 13.08, 12.14, 11.25, 14.29]
#}
#index = 0
#for temperature in forecast['daily']:
# index = index+1
#temperature=int(temperature)
#print(f"The forecast for Lisbon, Portugal for the next 5 days is:")
#print(f"Day {index}: {round(temperature)}ºC")
# Display the forecast in Lisbon such as:
# The forecast for Lisbon, Portugal for the next 5 days is:
# Day 1: 18ºC
# Day 2: 13ºC
# Day 3: 12ºC
# Day 4: 11ºC
# Day 5: 14ºC
# Import datetime
#from datetime import datetime
# Display the current date and time (no formatting)
#now=datetime.now()
#print(now)
# Display the current date and time following this format: Date: Jan 12, 2032 Time: 14:03
#new_date = now.strftime("Date: %b, %w, %Y, Time: %H:%M")
#print(new_date)
# Convert this time stamp 1705590204 into a date and display only the time using this format: 2:30am
#timestamp=1705590204
#new_time = datetime.fromtimestamp(timestamp)
#new_time = new_time.strftime("%I:%M%p")
#print(new_time)
# Exercise 1
#weather = {
#"city": "Lisbon",
# "country": "Portugal",
# "temperature": 17.94,
# "humidity": 77
#}
#city_name = weather['city']
#city_country = weather['country']
#city_temperature = weather['temperature']
#city_humidity = weather['humidity']
#fahrenheit = (city_temperature * 9 / 5) + 32
#print(
# f"It is {round(city_temperature)}ºC ({round(fahrenheit)}ºF) in {city_name}, {city_country} and the humidity level is {city_humidity}%."
#)
# Display the weather in Lisbon such as:
# It is 18ºC (64ºF) in Lisbon, Portugal, the humidity level is 77%.
# Exercise 2
#forecast = {
# "city": "Lisbon",
# "country": "Portugal",
# "daily": [17.76, 13.08, 12.14, 11.25, 14.29]
#}
#index = 0
#for temperature in forecast['daily']:
#index = index+1
# temperature=int(temperature)
# print(f"The forecast for Lisbon, Portugal for the next 5 days is:")
# print(f"Day {index}: {round(temperature)}ºC")
# Display the forecast in Lisbon such as:
# The forecast for Lisbon, Portugal for the next 5 days is:
# Day 1: 18ºC
# Day 2: 13ºC
# Day 3: 12ºC
# Day 4: 11ºC
# Day 5: 14ºC
#Create a new Repl
#Create a dictionary with 3 countries and their capital cities you’d like to visit
#Loop through each country and print out the following sentence:
#“Countries I’d like to visit”
#1: Canada (Capital city: Ottawa)
#2: France (Capital city: Paris)
#3: Germany (Capital city: Berlin)
#countries={"Spain":"Madrid", "Austria":"Vienna", "Italy":"Rome"}
#index= 0
#for country, capitals in countries.items():
#index= index + 1
#print(f"Countries I'd like to visit:")
#print(f"{index}: {country} (Capital city: {capitals})")
# Create a dictionary of 3 countries you’d like to visit as a key and their capital city a value
#countries = {"Romania": "Bucharest", "Germany": "Berlin", "France": "Paris"}
# Print out the dictionary
#print(countries)
# Remove your least favorite country from the dictionary
#countries.pop("Germany")
# Print out the dictionary
#print(countries)
# Add another country you'd like to visit
#countries["Italy"] = "Rome"
# Print out the dictionary
#print(countries)
# Display the capital of each country (one at a time, don't use a loop)
#print(f"The capital city of Romania is {countries['Romania']}")
#print(f"The capital city of Germany is {countries['Italy']}")
#print(f"The capital city of France is {countries['France']}")
#countries = ["Romania", "Australia", "Japan"]
#index=0
#for country in countries:
#print(f"My number{index+1} country is {country}")
#index=index+1
#Create a list of 3 countries you’d like to visit
#countries=["Romania","Italy", "France","Japan"]
# Print out the list
#print(countries)
# Remove the last country
#countries.remove("France")
# Print out the list
#print(countries)
# Add another element at the beginning of the list
#countries.insert(0,"USA")
# Print out the list
#print(countries)
# Print out the length of the list
#print(len(countries))
# Sort the list
#countries.sort()
# Print out the list
#print(countries)