34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
from weathersettings import Dict, List
|
|
|
|
|
|
# Formats forecast if retrieved successfully and displays semi raw data
|
|
def format_forecast(forecast_data: Dict) -> List[Dict]:
|
|
print(f"Displaying semi-structured semi-raw forecast:")
|
|
formatted_data = []
|
|
for period in forecast_data['properties']['periods']:
|
|
print(f"\n{period['name']}: {period['detailedForecast']}")
|
|
formatted_period = {
|
|
'name': period['name'],
|
|
'temperature': f"{period['temperature']['value']} Celsius",
|
|
'wind': f"{period['windSpeed']} {period['windDirection']}",
|
|
'short_forecast': period['shortForecast'],
|
|
'detailed_forecast': period['detailedForecast']
|
|
}
|
|
formatted_data.append(formatted_period)
|
|
return formatted_data
|
|
|
|
|
|
# Displays formatted forecast
|
|
def display_formatted_forecast(formatted_data: List[Dict]):
|
|
"""Displays the formatted forecast data."""
|
|
print(f"\n")
|
|
print(f"Displayingg formatted forecasts")
|
|
for period in formatted_data:
|
|
print(f"\n")
|
|
print(f"-" * 80)
|
|
print(f"{period['name']}")
|
|
print(f"Temperature: {period['temperature']}")
|
|
print(f"Wind: {period['wind']}")
|
|
print(f"Short Forecast: {period['short_forecast']}")
|
|
print(f"Detailed Forecast: {period['detailed_forecast']}")
|
|
print(f"-" * 80) |