baseballcommand 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ from .cli import cli
2
+
3
+ __all__ = ["cli"]
baseballcommand/cli.py ADDED
@@ -0,0 +1,23 @@
1
+ import argparse
2
+
3
+ from . import commands
4
+
5
+
6
+ def cli() -> None:
7
+ # List all possible functions here
8
+ FUNCTION_MAP = {
9
+ 'leagues': commands.get_leagues,
10
+ 'schedule': commands.get_todays_schedule
11
+ }
12
+
13
+ parser = argparse.ArgumentParser(
14
+ prog='BaseballCommand',
15
+ description="Get scores and stats from around the MLB."
16
+ )
17
+
18
+ parser.add_argument('command', choices=FUNCTION_MAP.keys())
19
+
20
+ args = parser.parse_args()
21
+
22
+ func = FUNCTION_MAP[args.command]
23
+ func()
@@ -0,0 +1,67 @@
1
+
2
+ from datetime import datetime
3
+ from zoneinfo import ZoneInfo
4
+
5
+ import requests
6
+
7
+ from . import utils
8
+
9
+
10
+ def get_leagues():
11
+ # This url responds with just MLB leagues
12
+ url = 'https://statsapi.mlb.com/api/v1/leagues?sportId=1'
13
+ response = requests.get(url)
14
+
15
+ if response.status_code == 200:
16
+ data = response.json()
17
+
18
+ leagues = data["leagues"]
19
+
20
+ for league in leagues:
21
+ # filter by AL and NL
22
+ if league["id"] == 103 or league["id"] == 104:
23
+ print(f'League id: {league["id"]} | League name: {league["name"]}')
24
+ return
25
+ else:
26
+ print(f'{response.status_code}')
27
+ return
28
+
29
+ def get_todays_schedule():
30
+ date = datetime.now(tz=ZoneInfo('America/New_York')).strftime('%Y-%m-%d')
31
+ url = f'https://statsapi.mlb.com/api/v1/schedule?sportId=1&date={date}'
32
+ response = requests.get(url)
33
+
34
+ if response.status_code == 200:
35
+ data = response.json()
36
+ # print(json.dumps(data, sort_keys=True, indent=4))
37
+ games = data["dates"][0]["games"]
38
+
39
+ # TODO: update this to handle days when no games occur (data["dates"][0]["totalGames"])
40
+ for game in games:
41
+ game_status = game["status"]["detailedState"]
42
+
43
+ game_date = game["gameDate"]
44
+ game_time_eastern = utils.UTC_to_EST(game_date)
45
+
46
+ away_team = game["teams"]["away"]["team"]["name"]
47
+ home_team = game["teams"]["home"]["team"]["name"]
48
+
49
+ # Game has not yet started
50
+ if game_status == 'Pre-Game' or game_status == 'Warmup':
51
+ print(f'{game_time_eastern} | {away_team} - {home_team}')
52
+ # Game is in-progress
53
+ elif game_status == 'Live':
54
+ # TODO: need to adjust game status matching
55
+ #TODO: I believe this needs to be pulled from a "game" object
56
+ away_score = game["teams"]["away"]["score"]
57
+ home_score = game["teams"]["home"]["score"]
58
+ print(f'{away_team} {away_score} - {home_score} {home_team}')
59
+ elif game_status == 'Final':
60
+ #TODO: need to adjust game status matching
61
+ away_score = game["teams"]["away"]["score"]
62
+ home_score = game["teams"]["home"]["score"]
63
+ print(f'Final: {away_team} {away_score} - {home_score} {home_team}')
64
+ return
65
+ else:
66
+ print(f'Response code: {response.status_code}')
67
+ return
@@ -0,0 +1,10 @@
1
+ from datetime import datetime
2
+ from zoneinfo import ZoneInfo
3
+
4
+
5
+ def UTC_to_EST(UTC_time):
6
+ dt = datetime.fromisoformat(UTC_time)
7
+ # Convert UTC to US Eastern time
8
+ eastern_dt = dt.astimezone(ZoneInfo('America/New_York'))
9
+ # Isolate just the time (game_date contains full date and time)
10
+ return eastern_dt.strftime('%I:%M %p')
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: baseballcommand
3
+ Version: 0.0.1
4
+ Summary: This is a tool that will retrieve Major League Baseball scores and stats.
5
+ License-Expression: MIT
6
+ Author: Owen Powell
7
+ Author-email: opowell2899@gmail.com
8
+ Requires-Python: >=3.12
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Requires-Dist: argparse (>=1.4.0,<2.0.0)
14
+ Requires-Dist: requests (>=2.34.2,<3.0.0)
@@ -0,0 +1,8 @@
1
+ baseballcommand/__init__.py,sha256=jVDF3cxpVRC6sobKO0GMvgD1V4vZ8ogqrx3vqhnCldU,39
2
+ baseballcommand/cli.py,sha256=hRdFHJ9lMJn4X3mAKp5De3WMlCCO4NhcRBEOOgE9DQE,505
3
+ baseballcommand/commands.py,sha256=2oeotvvS25lTQL7LtVfaaht8B7DYv3GLGEsuchyaQn0,2441
4
+ baseballcommand/utils.py,sha256=RUzj36OZxzw872-H09KYlh9nDjfCZIu613_yhyq1Oko,338
5
+ baseballcommand-0.0.1.dist-info/METADATA,sha256=6WcFABcZ01mlexF_ZzBWeIqfBrYjtMtHL_ptvf9yAvM,530
6
+ baseballcommand-0.0.1.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
7
+ baseballcommand-0.0.1.dist-info/entry_points.txt,sha256=3563K7xmfWe8S1VWfXcj6Uq5gopmFkm5usy2UiCovUg,44
8
+ baseballcommand-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ base=baseballcommand:cli
3
+