baseball/main.py

44 lines
1.0 KiB
Python

import requests
import os
from dotenv import load_dotenv
from rich.console import Console
from rich.table import Table
from rich import box
from data import get_game_data
from game import game_factory
load_dotenv()
console = Console()
def create_table(game):
table = Table(width=50, box=box.SQUARE)
table.add_column(game.status.title, width=32)
table.add_column("R", width=3, justify="right")
table.add_column("H", width=3, justify="right")
table.add_column("E", width=3, justify="right")
home_team = game.home_team
away_team = game.away_team
table.add_row(home_team.name,
str(home_team.runs),
str(home_team.hits),
str(home_team.errors))
table.add_row(away_team.name,
str(away_team.runs),
str(away_team.hits),
str(away_team.errors))
return table
games = get_game_data()
for event in games:
game = game_factory(event["competitions"][0])
table = create_table(game)
console.print(table)