initial commit
This commit is contained in:
49
main.py
Normal file
49
main.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Railway Route Activator — AI Devs 4, S01E05
|
||||
|
||||
Aplikacja aktywująca trasę kolejową X-01 przez API hub.ag3nts.org.
|
||||
Zbudowana w clean architecture z uwzględnieniem koncepcji z lekcji:
|
||||
- Architektura oparta o zdarzenia (EventBus)
|
||||
- Obsługa limitów API (rate limiting, retry z backoff)
|
||||
- Obsługa błędów 503 (symulacja przeciążenia serwera)
|
||||
- Logowanie i monitorowanie wszystkich interakcji
|
||||
- Konfiguracja przez zmienne środowiskowe
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from infrastructure.config import Config
|
||||
from infrastructure.event_bus import EventBus
|
||||
from infrastructure.api_client import RailwayApiClient
|
||||
from infrastructure.logger_setup import setup_logging, attach_event_logger
|
||||
from application.activate_route import ActivateRouteUseCase
|
||||
|
||||
|
||||
def main() -> None:
|
||||
load_dotenv()
|
||||
setup_logging()
|
||||
|
||||
config = Config.from_env()
|
||||
|
||||
event_bus = EventBus()
|
||||
attach_event_logger(event_bus)
|
||||
|
||||
api_client = RailwayApiClient(config, event_bus)
|
||||
|
||||
use_case = ActivateRouteUseCase(api_client, event_bus)
|
||||
|
||||
route_name = sys.argv[1] if len(sys.argv) > 1 else "x-01"
|
||||
result = use_case.execute(route_name)
|
||||
|
||||
if result.success:
|
||||
print(f"\nTrasa {result.route.name} aktywowana pomyślnie!")
|
||||
if result.flag:
|
||||
print(f"Flaga: {result.flag}")
|
||||
else:
|
||||
print(f"\nBłąd: {result.error}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user