baseballcommand 0.0.1__tar.gz
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.
- baseballcommand-0.0.1/PKG-INFO +14 -0
- baseballcommand-0.0.1/pyproject.toml +25 -0
- baseballcommand-0.0.1/src/baseballcommand/__init__.py +3 -0
- baseballcommand-0.0.1/src/baseballcommand/cli.py +23 -0
- baseballcommand-0.0.1/src/baseballcommand/commands.py +67 -0
- baseballcommand-0.0.1/src/baseballcommand/utils.py +10 -0
|
@@ -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,25 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "baseballcommand"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "This is a tool that will retrieve Major League Baseball scores and stats."
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Owen Powell",email = "opowell2899@gmail.com"}
|
|
7
|
+
]
|
|
8
|
+
license = "MIT"
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"argparse (>=1.4.0,<2.0.0)",
|
|
12
|
+
"requests (>=2.34.2,<3.0.0)"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.poetry.scripts]
|
|
16
|
+
base = "baseballcommand:cli" # CLI entry point
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
20
|
+
build-backend = "poetry.core.masonry.api"
|
|
21
|
+
|
|
22
|
+
[dependency-groups]
|
|
23
|
+
dev = [
|
|
24
|
+
"ruff (>=0.16.5,<0.17.0)"
|
|
25
|
+
]
|
|
@@ -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')
|