Skip to content

Commit

Permalink
Merge pull Weather Forcasting App request #20 from i-OmSharma/Om4
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsamirr authored Oct 29, 2023
2 parents c0cef7b + d6ade7f commit 11af307
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Weather_Forecasting_App/weather_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests

def get_weather(api_key, city):
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"
response = requests.get(url)
data = response.json()
return data

def display_weather(data):
print(data) # Add this line to print the entire API response

if data["cod"] != "404":
if "main" in data:
main = data["main"]
temperature = main["temp"] - 273.15
weather_desc = data["weather"][0]["description"]
print(f"Temperature: {temperature:.2f}°C")
print(f"Weather: {weather_desc}")
else:
print("Unexpected response format from the API. Please check the API documentation.")
else:
print("City not found. Please check the spelling.")



if __name__ == "__main__":
api_key = "YOUR_API_KEY" # Replace with your OpenWeatherMap API key
city = input("Enter city name: ")
weather_data = get_weather(api_key, city)
display_weather(weather_data)

0 comments on commit 11af307

Please sign in to comment.