Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,5 @@ cython_debug/
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,jupyternotebooks,python

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
.python-version
.envrc
101 changes: 51 additions & 50 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks [dependabot skip]"
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: ^output/
args: [--unsafe]
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: [--line-length=80]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--max-line-length=80]
additional_dependencies: [flake8-docstrings, flake8-pyproject]
# files: ^my_appname/|^test_suite_name/
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black, --line-length=80]
- repo: https://github.com/jackdewinter/pymarkdown
rev: v0.9.12
hooks:
- id: pymarkdown
exclude: ^.github/
args: [-d, "MD014", scan]
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies: ["pydocstyle[toml]"]
exclude: ^migrations/|__init__.py
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: ["--silent", "-c", "pyproject.toml", "-r"]
additional_dependencies: ["bandit[toml]"]
- repo: https://github.com/python-poetry/poetry
rev: "1.6.0"
hooks:
- id: poetry-check
# - id: poetry-lock
- id: poetry-export
- id: check-toml
- id: check-merge-conflict
- id: end-of-file-fixer

# - repo: https://github.com/renovatebot/pre-commit-hooks
# rev: 39.69.2
# hooks:
# - id: renovate-config-validator
# files: ^renovate\.json$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
hooks:
- id: ruff
args: ["--output-format=concise"]
name: "lint with ruff"
- id: ruff-format
name: "format with ruff"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.19.1" # Use the sha / tag you want to point at
hooks:
- id: mypy
name: "run mypy"
additional_dependencies:
- pydantic
- types-requests

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.18
hooks:
# Update the uv lockfile
- id: uv-lock
- id: uv-export
name: "Export dependencies to 'requirements.txt'"
args:
[
"--no-hashes",
"--no-dev",
"--no-emit-project",
"--output-file=requirements.txt",
]
- id: uv-export
name: "Export dev dependencies to 'requirements-dev.txt'"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements.txt",
"--no-hashes",
"--no-emit-project",
"--output-file=requirements-dev.txt",
]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
Expand Down
40 changes: 25 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
"source.fixAll": "always",
"source.organizeImports": "always"
},
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
"autoDocstring.startOnNewLine": true,
"beautify.language": {
"html": ["htm", "html", "django-html"]
},
"black-formatter.args": ["--line-length=80"],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"emmet.includeLanguages": {
Expand All @@ -27,33 +26,44 @@
},
"files.eol": "\n",
"files.exclude": {
"**/__pycache__": true
"**/__pycache__": true,
"**/.mypy_cache": true,
"**/.pytest_cache": true,
"**/.ruff_cache": true,
"**/.cache": true
},
"flake8.args": ["--max-line-length=80"],
"git.alwaysSignOff": true,
"git.enableCommitSigning": true,
"html.format.indentHandlebars": true,
"html.format.templating": true,
"isort.args": ["--profile", "black", "--src=${workspaceFolder}"],
"material-icon-theme.languages.associations": {
"jinja-html": "django"
},
"pylint.args": [
"--enable=pylint.extensions.docparams",
"--load-plugins",
"pylint-pydantic",
"pylint-pytest"
],
"mypy-type-checker.args": ["--strict"],
"mypy-type-checker.importStrategy": "fromEnvironment",
"python.analysis.autoImportCompletions": true,
"python.analysis.autoImportUserSymbols": true,
"python.analysis.extraPaths": [],
"python.analysis.indexing": true,
"python.analysis.stubPath": "/home/seapagan/stubs",
"python.analysis.typeCheckingMode": "basic",
"python.analysis.typeCheckingMode": "off", // using the mypy extension instead
"python.languageServer": "Pylance",
"python.pythonPath": "./.venv/bin/python",
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"ruff.organizeImports": false
"ruff.fixAll": false,
"ruff.organizeImports": true,
"python.analysis.autoFormatStrings": true,
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/*/**": true,
"**/.hg/store/**": true,
"**/.venv/**": true,
"**/.mypy_cache/**": true,
"**/.pytest_cache/**": true,
"**/.ruff_cache/**": true
},
"markdownlint.ignore": ["CHANGELOG.md"]
}
34 changes: 13 additions & 21 deletions generate_trek.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,45 @@

Produce JSON dumps of Star Trek data suitable for adding to an API.
"""
import sys

import colorama
from rich import print # pylint: disable=redefined-builtin
from rich import print as rprint

from lib.trekpedia import Trekpedia

MAIN_URL = "https://en.wikipedia.org/wiki/Star_Trek"
JSON_TEMPLATE = "output/star_trek_series_{}_{}_episodes.json"
from trekpedia import JSON_TEMPLATE, MAIN_URL, Trekpedia, save_json


# ---------------------------------------------------------------------------- #
# Main Code #
# ---------------------------------------------------------------------------- #
def main(_args):
def main() -> None:
"""Run the main program, parse and save data from Wikipedia."""
try:
trekpedia = Trekpedia(summary_url=MAIN_URL, json_template=JSON_TEMPLATE)

colorama.init()

print(
rprint(
"Trekpedia : Parse '[cyan]Star Trek[/cyan]' "
"data from the Web and save as JSON.\n"
)
print("\u00a9 2023 Grant Ramsay <grant@gnramsay.com>\n")
print(f"Version {trekpedia.version}\n")
rprint("\u00a9 2023 Grant Ramsay <grant@gnramsay.com>\n")
rprint(f"Version {trekpedia.version}\n")

# ---- get the series info and save to a JSON file for later use. ---- #
print("Getting Series Data ... ", end="")
rprint("Getting Series Data ... ", end="")
trekpedia.get_series_info()
trekpedia.save_json(
"output/star_trek_series_info.json", trekpedia.series_data
)
print("Done!\n")
save_json("output/star_trek_series_info.json", trekpedia.series_data)
rprint("Done!\n")

# ----------- loop through each series and parse then save ----------- #
for series_data in trekpedia.series_data.items():
# for now we ignore 'Prodigy' until I re-visit the code.
if series_data[0] not in [11]:
trekpedia.parse_series(series_data)
except KeyboardInterrupt:
print("\r", " " * 80)
print("[red][bold]Escape Pressed, processing ABORTED.\n")
rprint("\r", " " * 80)
rprint("[red][bold]Escape Pressed, processing ABORTED.\n")


# ---------------------------------------------------------------------------- #
# Actually run our code, unless we have been imported #
# ---------------------------------------------------------------------------- #
if __name__ == "__main__":
main(sys.argv[1:])
main()
Loading