baseball/main.py

47 lines
1.3 KiB
Python

from dotenv import load_dotenv
from rich.console import Console
import argparse
from data import get_game_data
from game import game_factory
from output import output_game
load_dotenv()
console = Console()
def init_games():
games = []
events = get_game_data()
for event in events:
games.append(game_factory(event["competitions"][0]))
return games
# Parse options for teams
def main():
arg_parser = argparse.ArgumentParser(prog="Baseball Score CLI",
description="Get the current scores of the games.")
arg_parser.add_argument('-t', '--team',
help="Give a specific team to get scores for.",
required=False)
args = arg_parser.parse_args()
events = init_games()
if args.team:
found_event= filter(lambda e: e.home_team.abbr.lower() == args.team.lower() or e.away_team.abbr.lower() == args.team.lower(), events)
if found_event:
event = list(found_event).pop()
table = output_game(event)
console.print(table)
else:
print(f"Team not found: {args.team}")
else:
for event in events:
table = output_game(event)
console.print(table)
if __name__ == "__main__":
main()