baseballcommand 0.0.1__tar.gz → 0.0.3__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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: baseballcommand
3
- Version: 0.0.1
4
- Summary: This is a tool that will retrieve Major League Baseball scores and stats.
3
+ Version: 0.0.3
4
+ Summary: This is a tool that will retrieve Major League Baseball scores and stats in your command line.
5
5
  License-Expression: MIT
6
6
  Author: Owen Powell
7
7
  Author-email: opowell2899@gmail.com
@@ -10,5 +10,6 @@ Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.12
11
11
  Classifier: Programming Language :: Python :: 3.13
12
12
  Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Programming Language :: Python :: 3.15
13
14
  Requires-Dist: argparse (>=1.4.0,<2.0.0)
14
15
  Requires-Dist: requests (>=2.34.2,<3.0.0)
@@ -1,7 +1,11 @@
1
+ [build-system]
2
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
1
5
  [project]
2
6
  name = "baseballcommand"
3
- version = "0.0.1"
4
- description = "This is a tool that will retrieve Major League Baseball scores and stats."
7
+ version = "0.0.3"
8
+ description = "This is a tool that will retrieve Major League Baseball scores and stats in your command line."
5
9
  authors = [
6
10
  {name = "Owen Powell",email = "opowell2899@gmail.com"}
7
11
  ]
@@ -15,10 +19,6 @@ dependencies = [
15
19
  [tool.poetry.scripts]
16
20
  base = "baseballcommand:cli" # CLI entry point
17
21
 
18
- [build-system]
19
- requires = ["poetry-core>=2.0.0,<3.0.0"]
20
- build-backend = "poetry.core.masonry.api"
21
-
22
22
  [dependency-groups]
23
23
  dev = [
24
24
  "ruff (>=0.16.5,<0.17.0)"
@@ -0,0 +1,24 @@
1
+ import argparse
2
+
3
+ from .commands import players, schedule
4
+
5
+
6
+ def cli() -> None:
7
+ parser = argparse.ArgumentParser(prog='BaseballCommand')
8
+ subparsers = parser.add_subparsers(dest='command', required=True)
9
+
10
+ subparsers.add_parser('leagues', help='Return a list of MLB leagues.')
11
+ subparsers.add_parser('schedule', help='Return a list of todays games.')
12
+
13
+ player_parser = subparsers.add_parser('player', help='Return stats for the specified player for the current season.')
14
+ player_parser.add_argument('first_name')
15
+ player_parser.add_argument('last_name')
16
+
17
+ args = parser.parse_args()
18
+
19
+ if args.command == 'player':
20
+ players.player_search(f'{args.first_name}', f'{args.last_name}')
21
+ elif args.command == 'leagues':
22
+ schedule.get_leagues()
23
+ elif args.command == 'schedule':
24
+ schedule.get_todays_schedule()
@@ -0,0 +1,41 @@
1
+
2
+ import requests
3
+
4
+
5
+ # TODO: improve name matching. Example: searching for Pete Crowe-Armstrong returns Pete Alonso
6
+ # solution: check name match on JSON return?
7
+ def player_search(first_name, last_name):
8
+ url = (f'https://statsapi.mlb.com/api/v1/people/search?names={first_name.lower()}%20'
9
+ f'{last_name.lower()}'
10
+ f'&active=True'
11
+ f'&sportIDs=1'
12
+ f'&limit=1')
13
+
14
+ response = requests.get(url)
15
+
16
+ if response.status_code == 200:
17
+ data = response.json()
18
+
19
+ # print(json.dumps(data, sort_keys=True, indent=4))
20
+
21
+ player = data["people"][0]
22
+ player_id = player["id"]
23
+
24
+ # TODO: change URL if player is a pitcher
25
+ stats_url = f'https://statsapi.mlb.com/api/v1/people/{player_id}/stats?stats=season&group=hitting'
26
+
27
+ stats_response = requests.get(stats_url)
28
+
29
+ if stats_response.status_code == 200:
30
+ # stats_data = stats_response.json()
31
+
32
+ # print(json.dumps(stats_data, sort_keys=True, indent=4))
33
+
34
+ # stat = stats_data["stats"][0]["splits"][0]["stat"]
35
+ print(f'{"Games Played | ":14}{"At Bats | ":9}{"Hits | ":6}{"Runs | ":6}{"RBI | ":5}{"Home Runs | ":11}'
36
+ f'{"Doubles | ":9}{"Triples | ":9}{"AVG | ":5}{"OBP | ":5}{"OPS | ":5}{"SLG | ":5}')
37
+ print('-' * 100)
38
+
39
+ else:
40
+ print(f'Response: {response.status_code}')
41
+ return
@@ -1,10 +1,9 @@
1
-
2
1
  from datetime import datetime
3
2
  from zoneinfo import ZoneInfo
4
3
 
5
4
  import requests
6
5
 
7
- from . import utils
6
+ from baseballcommand import utils
8
7
 
9
8
 
10
9
  def get_leagues():
@@ -23,7 +22,7 @@ def get_leagues():
23
22
  print(f'League id: {league["id"]} | League name: {league["name"]}')
24
23
  return
25
24
  else:
26
- print(f'{response.status_code}')
25
+ print(f'Response: {response.status_code}')
27
26
  return
28
27
 
29
28
  def get_todays_schedule():
@@ -47,7 +46,7 @@ def get_todays_schedule():
47
46
  home_team = game["teams"]["home"]["team"]["name"]
48
47
 
49
48
  # Game has not yet started
50
- if game_status == 'Pre-Game' or game_status == 'Warmup':
49
+ if game_status == 'Scheduled':
51
50
  print(f'{game_time_eastern} | {away_team} - {home_team}')
52
51
  # Game is in-progress
53
52
  elif game_status == 'Live':
@@ -1,23 +0,0 @@
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()