generated from mwc/lab_weather
couldnt get past my error message
Yellow wiggly lines under weather_apis.py in the beginning. Tried to follow error message which says that apis.py isn't included in the directory. I tried to move it into lab_weather. It still doesn't work.
This commit is contained in:
parent
86a3efa082
commit
953cc4de24
|
@ -21,4 +21,57 @@ def print_weather(location=None, metric=False, verbose=False):
|
|||
When metric is True, prints out the weather in metric units.
|
||||
When verbose is True, prints out a more detailed report.
|
||||
"""
|
||||
print("Not finished...") # YOUR CODE HERE!
|
||||
|
||||
if location:
|
||||
coordinates = geocode_location(location)
|
||||
if not coordinates:
|
||||
print("Error: Location not found.")
|
||||
return
|
||||
else:
|
||||
coordinates = estimate_location()
|
||||
if not coordinates:
|
||||
print("Error: Unable to estimate location.")
|
||||
return
|
||||
|
||||
|
||||
office_info = get_weather_office(coordinates['lat'], coordinates['lng'])
|
||||
if not office_info:
|
||||
print("Error: Weather office not found for this location.")
|
||||
return
|
||||
|
||||
|
||||
forecast = get_forecast(office_info['office'], office_info['x'], office_info['y'], metric=metric)
|
||||
if not forecast:
|
||||
print("Error: Forecast data is unavailable.")
|
||||
return
|
||||
|
||||
temp_unit = "°C" if metric else "°F"
|
||||
print(f"Weather Forecast for {location or 'your location'}:")
|
||||
for period in forecast:
|
||||
|
||||
temp = period['temperature']
|
||||
description = period['description']
|
||||
wind = period['wind_speed']
|
||||
wind_dir = period['wind_direction']
|
||||
|
||||
print(f"{period['name']}: {temp}{temp_unit}, {description}")
|
||||
|
||||
|
||||
if verbose:
|
||||
print(f" Wind: {wind} {wind_dir}")
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from weather.weather_main import print_weather # Ensure the correct import path if your file is renamed
|
||||
|
||||
def weather_cli():
|
||||
"""Provides a command-line interface for weather.
|
||||
This function creates an ArgumentParser, which parses command line arguments.
|
||||
Then it calls `print_weather` with the provided arguments.
|
||||
"""
|
||||
parser = ArgumentParser("weather", description="Prints out a weather report")
|
||||
parser.add_argument("-l", "--location", help="Location for weather forecast")
|
||||
parser.add_argument("-m", "--metric", action="store_true", help="Use metric units")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
|
||||
args = parser.parse_args()
|
||||
print_weather(location=args.location, metric=args.metric, verbose=args.verbose)
|
||||
|
||||
|
|
Loading…
Reference in New Issue