Egy komplexebb program szemléltetésére kiválóan alkalmas egy Aszinkron Időjárás- és Deviza-lekérdező Rendszer.
------------------
class WeatherForexSystem:
def __init__(self, location: str, base_currency: str, target_currency: str):
self.location = location
self.base_currency = base_currency.upper()
self.target_currency = target_currency.upper()
def fetch_weather(self) -> dict:
return {
"current_condition": [
{
"temp_C": "22",
"lang_hu": [{"value": "tiszta égbolt"}]
}
]
}
def fetch_exchange_rate(self) -> dict:
return {"rate": 389.75}
def run(self):
print(f"Adatok lekérése a következő helyhez: {self.location}...\n")
weather_data = self.fetch_weather()
forex_data = self.fetch_exchange_rate()
self.display_report(weather_data, forex_data)
def display_report(self, weather_data, forex_data):
print("=" * 40)
print(" KOMPLEX INFORMÁCIÓS JELENTÉS")
print("=" * 40)
current = weather_data['current_condition'][0]
print(f"Helyszín: {self.location.capitalize()}")
print(f"Hőmérséklet: {current['temp_C']} °C")
print(f"Időjárás: {current['lang_hu'][0]['value']}")
print("-" * 40)
print(f"Deviza: 1 {self.base_currency} = {forex_data['rate']} {self.target_currency}")
print("=" * 40)
if __name__ == "__main__":
app = WeatherForexSystem(location="budapest", base_currency="EUR", target_currency="HUF")
app.run()
---------------
Adatok lekérése a következő helyhez: budapest...
========================================
KOMPLEX INFORMÁCIÓS JELENTÉS
========================================
Helyszín: Budapest
Hőmérséklet: 22 °C
Időjárás: tiszta égbolt
----------------------------------------
Deviza: 1 EUR = 389.75 HUF
========================================
Nincsenek megjegyzések:
Megjegyzés küldése