Skip to content

📝 Add docstrings to og-test-feature #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: og-test-feature
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions weather-app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

def get_temperature(city_name, api_key):
"""
Fetches the current temperature in Fahrenheit for a given U.S. city
using the OpenWeatherMap API.

Parameters:
city_name (str): The name of the U.S. city.
api_key (str): Your OpenWeatherMap API key.

Retrieves the current temperature in Fahrenheit for a specified U.S. city using the OpenWeatherMap API.

Args:
city_name: Name of the U.S. city.
api_key: OpenWeatherMap API key.

Returns:
float: Current temperature in Fahrenheit if successful.
None: If an error occurs or the data cannot be retrieved.
The current temperature in Fahrenheit as a float if successful, or None if an error occurs or data is unavailable.
"""
if not api_key or not isinstance(api_key, str):
print("Error: Invalid or missing API key.")
Expand Down Expand Up @@ -48,6 +46,11 @@ def get_temperature(city_name, api_key):
return None

def main():
"""
Prompts the user for a U.S. city and displays its current temperature in Fahrenheit.

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.
"""
import os
api_key = os.getenv('OPENWEATHER_API_KEY')
if not api_key:
Expand Down