Skip to content

Commit

Permalink
pypi project format
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-thompson committed Dec 7, 2024
1 parent 3786a2c commit 01fb3ed
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 173 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload release to PyPI

on:
push:
tags:
- '*'

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/sportify/
permissions:
id-token: write
steps:
- name: Checkout source
uses: actions/checkout@main
- name: Install Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build tool
run: >-
pip install build
- name: Build package
run: >-
python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__
*.pyc
*.pyc
dist
_version.py
172 changes: 0 additions & 172 deletions main.py

This file was deleted.

11 changes: 11 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: clean build install run test
DEFAULT: install

clean:
rm -rf dist .tox
build: clean
python3 -m build
install: build
pipx install dist/*.tar.gz --force
run:
sportify
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
dynamic = ["version"]
name = "sportify"
description = "Fetch sports data from CLI"
readme = "README.md"
requires-python = ">=3.7"
license = {file = "LICENSE"}
keywords = ["sports", "athletics", "data", "executable", "application", "cli", "espn"]
authors = [
{name = "Jacob A. Thompson", email = "jacobalthompson@gmail.com"}
]
maintainers = [
{name = "Jacob A. Thompson", email = "jacobalthompson@gmail.com"}
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Topic :: Games/Entertainment",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
]
dependencies = ["python-dateutil", "requests", "simple_term_menu"]

[project.urls]
"Homepage" = "https://github.com/jacob-thompson/sportify"
"Bug Reports" = "https://github.com/jacob-thompson/sportify/issues"

[project.gui-scripts]
sportify = "sportify.main:main"

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "_version.py"
Empty file added src/sportify/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions src/sportify/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .sportify import *

def main():
print(f"{PROJECT} {PROJECT_URL}")

leagues = list(MENU_DATA.keys())
try: # get input & request output
menu = Menu(leagues, title = "LEAGUE", clear_screen = True)
entry = menu.show()
selected_league = leagues[entry]

teams = [MENU_DATA[league] for league in leagues if league == selected_league]
assert teams != []

submenu = Menu(teams[0], title = "TEAM", clear_screen = True)
entry = submenu.show()
selected_team = teams[0][entry]

data = request_data(selected_league.split()[1], selected_team.split()[1])
except BadAPIRequest as error:
print(error)
raise SystemExit(EXIT_FAIL)
except TypeError: # occurs when user presses Escape or Q to quit
raise SystemExit(EXIT_OK)
except AssertionError: # impossible
print(UNEXPECTED)
raise SystemExit(EXIT_FAIL)

output(data)
raise SystemExit(EXIT_OK)

if __name__ == "__main__":
main()
69 changes: 69 additions & 0 deletions src/sportify/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
PROJECT = "sportify"
PROJECT_URL = f"https://github.com/jacob-thompson/{PROJECT}"
API_URL = "https://site.api.espn.com/apis/site/v2/sports/"

ERR = "ERROR:"
REPORT = f"PLEASE SUBMIT AN ISSUE REPORT:\n\t{PROJECT_URL}/issues"
UNEXPECTED = f"{ERR} AN UNEXPECTED ERROR HAS OCCURRED\n{REPORT}"

SPORTS = {
"football": {
"NFL"
},
"basketball": {
"NBA"
},
"baseball": {
"MLB"
},
"hockey": {
"NHL"
}
}

MENU_DATA = {
"[1] NFL": [
"[1] ARI", "[2] ATL", "[3] BAL", "[4] BUF",
"[5] CAR", "[6] CHI", "[7] CIN", "[8] CLE",
"[9] DAL", "[0] DEN", "[a] DET", "[b] GB",
"[c] HOU", "[d] IND", "[e] JAX", "[f] KC",
"[g] LV", "[h] LAC", "[i] LAR", "[j] MIA",
"[k] MIN", "[l] NE", "[m] NO", "[n] NYG",
"[o] NYJ", "[p] PHI", "[q] PIT", "[r] SF",
"[s] SEA", "[t] TB", "[u] TEN", "[v] WSH"
],
"[2] NBA": [
"[1] ATL", "[2] BOS", "[3] BKN", "[4] CHA",
"[5] CHI", "[6] CLE", "[7] DAL", "[8] DEN",
"[9] DET", "[0] GS", "[a] HOU", "[b] IND",
"[c] LAC", "[d] LAL", "[e] MEM", "[f] MIA",
"[g] MIL", "[h] MIN", "[i] NO", "[j] NY",
"[k] OKC", "[l] ORL", "[m] PHI", "[n] PHX",
"[o] POR", "[p] SAC", "[q] SA", "[r] TOR",
"[s] UTAH", "[t] WSH"
],
"[3] MLB": [
"[1] ARI", "[2] ATL", "[3] BAL", "[4] BOS",
"[5] CHW", "[6] CHC", "[7] CIN", "[8] CLE",
"[9] COL", "[0] DET", "[a] HOU", "[b] KC",
"[c] LAA", "[d] LAD", "[e] MIA", "[f] MIL",
"[g] MIN", "[h] NYY", "[i] NYM", "[j] OAK",
"[k] PHI", "[l] PIT", "[m] SD", "[n] SF",
"[o] SEA", "[p] STL", "[q] TB", "[r] TEX",
"[s] TOR", "[t] WSH"
],
"[4] NHL": [
"[1] ANA", "[2] BOS", "[3] BUF", "[4] CGY",
"[5] CAR", "[6] CHI", "[7] COL", "[8] CBJ",
"[9] DAL", "[0] DET", "[a] EDM", "[b] FLA",
"[c] LA", "[d] MIN", "[e] MTL", "[f] NSH",
"[g] NJ", "[h] NYI", "[i] NYR", "[j] OTT",
"[k] PHI", "[l] PIT", "[m] SJ", "[n] SEA",
"[o] STL", "[p] TB", "[q] TOR", "[r] UTAH",
"[s] VAN", "[t] VGK", "[u] WSH", "[v] WPG"
]
}

API_OK = 200
EXIT_OK = 0
EXIT_FAIL = 1
Loading

0 comments on commit 01fb3ed

Please sign in to comment.