Skip to content

Commit 7076966

Browse files
📝 Add docstrings to og-test-feature
Docstrings generation was requested by @omar-coderabbitai. * #2 (comment) The following files were modified: * `weather-app.py`
1 parent b27abc1 commit 7076966

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

weather-app.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
def get_temperature(city_name, api_key):
44
"""
5-
Fetches the current temperature in Fahrenheit for a given U.S. city
6-
using the OpenWeatherMap API.
7-
8-
Parameters:
9-
city_name (str): The name of the U.S. city.
10-
api_key (str): Your OpenWeatherMap API key.
11-
5+
Retrieves the current temperature in Fahrenheit for a specified U.S. city using the OpenWeatherMap API.
6+
7+
Args:
8+
city_name: Name of the U.S. city.
9+
api_key: OpenWeatherMap API key.
10+
1211
Returns:
13-
float: Current temperature in Fahrenheit if successful.
14-
None: If an error occurs or the data cannot be retrieved.
12+
The current temperature in Fahrenheit as a float if successful, or None if an error occurs or data is unavailable.
1513
"""
1614
if not api_key or not isinstance(api_key, str):
1715
print("Error: Invalid or missing API key.")
@@ -48,6 +46,11 @@ def get_temperature(city_name, api_key):
4846
return None
4947

5048
def main():
49+
"""
50+
Prompts the user for a U.S. city and displays its current temperature in Fahrenheit.
51+
52+
Retrieves the OpenWeatherMap API key from the environment, requests the city name from the user, and prints the current temperature if available. Displays error messages for missing API key, empty city input, or failed data retrieval.
53+
"""
5154
import os
5255
api_key = os.getenv('OPENWEATHER_API_KEY')
5356
if not api_key:

0 commit comments

Comments
 (0)