Skip to content

Commit b5287db

Browse files
Update weather-app.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent e55477a commit b5287db

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

weather-app.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ def get_temperature(city_name, api_key):
1717
return None
1818

1919
def main():
20-
api_key = "YOUR_API_KEY_HERE" # Replace this with your OpenWeatherMap API key
20+
import os
21+
api_key = os.getenv('OPENWEATHER_API_KEY')
22+
if not api_key:
23+
print("Error: Please set the OPENWEATHER_API_KEY environment variable")
24+
return
25+
2126
city = input("Enter a major U.S. city: ").strip()
22-
27+
if not city:
28+
print("Error: City name cannot be empty")
29+
return
30+
2331
temp = get_temperature(city, api_key)
2432
if temp is not None:
2533
print(f"The current temperature in {city.title()} is {temp:.1f}°F.")

0 commit comments

Comments
 (0)