From 34b7668e8852b2475191407a5d78073b5ab4c9e5 Mon Sep 17 00:00:00 2001 From: TheMagicHatCoder Date: Wed, 9 Jul 2025 12:22:01 -0500 Subject: [PATCH] Create main.py --- WeatherBotCLI/main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 WeatherBotCLI/main.py diff --git a/WeatherBotCLI/main.py b/WeatherBotCLI/main.py new file mode 100644 index 00000000..161b35dc --- /dev/null +++ b/WeatherBotCLI/main.py @@ -0,0 +1,30 @@ +import requests + +def get_weather(city, api_key): + url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric" + response = requests.get(url) + data = response.json() + + if response.status_code != 200: + return f"Error: {data.get('message', 'Something went wrong.')}" + + weather = data['weather'][0]['description'] + temp = data['main']['temp'] + feels_like = data['main']['feels_like'] + humidity = data['main']['humidity'] + wind = data['wind']['speed'] + + return (f"🌍 Weather in {city}:\n" + f"☁️ Condition: {weather}\n" + f"🌡️ Temp: {temp}°C (feels like {feels_like}°C)\n" + f"💧 Humidity: {humidity}%\n" + f"💨 Wind Speed: {wind} m/s") + + +API_KEY = "abd39iirii93rYOURAPIKEYHERE" + +while True: + city = input("Enter a city (or type 'exit' to quit): ") + if city.lower() == 'exit': + break + print(get_weather(city, API_KEY))