From 1994fdeac7d49c31492d362fb25857dcac1a2c30 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Sat, 2 Nov 2024 21:42:56 +0100 Subject: [PATCH] Initial version --- .gitignore | 83 ++++++++++++++++++++++++++++++++++++ README.md | 5 +++ pyproject.toml | 72 +++++++++++++++++++++++++++++++ requirements.in | 2 + requirements.txt | 94 +++++++++++++++++++++++++++++++++++++++++ src/alfagok/__init__.py | 1 + src/alfagok/main.py | 23 ++++++++++ tox.ini | 21 +++++++++ wordlist/create_list.py | 36 ++++++++++++++++ 9 files changed, 337 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 requirements.in create mode 100644 requirements.txt create mode 100644 src/alfagok/__init__.py create mode 100644 src/alfagok/main.py create mode 100644 tox.ini create mode 100644 wordlist/create_list.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..505b835 --- /dev/null +++ b/.gitignore @@ -0,0 +1,83 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Logging: +*.log +*.log.* + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Ipython Notebook +.ipynb_checkpoints + +# Various Python project related +local_settings.py +projects.yaml +settings.py + +# IDE +.idea + +# vim +*.swp +*.swo + +# ctags +tags +TAGS + +# settings +settings.py +rq_settings.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..aa6aa3a --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# alfagok + +Omdat Nederlanders ook [alphaguess](https://alphaguess.com) willen spelen :) + +My own implementation of an alphaguess like game with custom word lists, tailored to be used with a Dutch source. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..46990ae --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,72 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "webhaak" +version = "0.6.0-pre" +authors = [ + {name = "Michiel Scholten", email = "michiel@diginaut.net"}, +] +description= "Simple webhook service to update and deploy sites and do other maintenance and automatic tasks" +readme = "README.rst" +requires-python = ">=3.8" +keywords = ["webhook", "api", "automation", "CI/CD", "Git", "monitoring"] +license = {text = "Apache"} +classifiers = [ + "Framework :: FastAPI", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", +] +dependencies = [ + "fastapi[all]", + "pydantic>2.0", + "strictyaml", + "gitpython", + "rq" +] +# dynamic = ["version"] + +[project.scripts] +my-script = "webhaak:app" + +[project.urls] +"Homepage" = "https://github.com/aquatix/webhaak" +"Bug Tracker" = "https://github.com/aquatix/webhaak/issues" + +[tool.ruff] +exclude = [ + ".git", + "__pycache__", + "docs/source/conf.py", + "build", + "dist", + "example_config/gunicorn_webhaak_conf.py", + "example_config/rq_settings.example.py", + "example_config/settings.py", +] +line-length = 120 + +[tool.ruff.format] +# Use single quotes for non-triple-quoted strings. +quote-style = "single" + +[tool.ruff.lint] +ignore = ["D203", "D213"] +select = [ + "C9", + "D", + "E", + "F", + "I", + "W", +] + +[tool.ruff.lint.isort] +section-order = ["future", "standard-library","third-party", "first-party", "testing", "local-folder"] + +[tool.ruff.lint.isort.sections] +testing = ["tests"] + +[tool.ruff.lint.mccabe] +max-complexity = 10 diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..0b952f5 --- /dev/null +++ b/requirements.in @@ -0,0 +1,2 @@ +fastapi[standard] +pydantic-settings diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f0be8d4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,94 @@ +# This file was autogenerated by uv via the following command: +# uv pip compile requirements.in +annotated-types==0.7.0 + # via pydantic +anyio==4.6.2.post1 + # via + # httpx + # starlette + # watchfiles +certifi==2024.8.30 + # via + # httpcore + # httpx +click==8.1.7 + # via + # typer + # uvicorn +dnspython==2.7.0 + # via email-validator +email-validator==2.2.0 + # via fastapi +fastapi==0.115.4 + # via -r requirements.in +fastapi-cli==0.0.5 + # via fastapi +h11==0.14.0 + # via + # httpcore + # uvicorn +httpcore==1.0.6 + # via httpx +httptools==0.6.4 + # via uvicorn +httpx==0.27.2 + # via fastapi +idna==3.10 + # via + # anyio + # email-validator + # httpx +jinja2==3.1.4 + # via fastapi +markdown-it-py==3.0.0 + # via rich +markupsafe==3.0.2 + # via jinja2 +mdurl==0.1.2 + # via markdown-it-py +pydantic==2.9.2 + # via + # fastapi + # pydantic-settings +pydantic-core==2.23.4 + # via pydantic +pydantic-settings==2.6.1 + # via -r requirements.in +pygments==2.18.0 + # via rich +python-dotenv==1.0.1 + # via + # pydantic-settings + # uvicorn +python-multipart==0.0.17 + # via fastapi +pyyaml==6.0.2 + # via uvicorn +rich==13.9.4 + # via typer +shellingham==1.5.4 + # via typer +sniffio==1.3.1 + # via + # anyio + # httpx +starlette==0.41.2 + # via fastapi +typer==0.12.5 + # via fastapi-cli +typing-extensions==4.12.2 + # via + # fastapi + # pydantic + # pydantic-core + # typer +uvicorn==0.32.0 + # via + # fastapi + # fastapi-cli +uvloop==0.21.0 + # via uvicorn +watchfiles==0.24.0 + # via uvicorn +websockets==13.1 + # via uvicorn diff --git a/src/alfagok/__init__.py b/src/alfagok/__init__.py new file mode 100644 index 0000000..055ff74 --- /dev/null +++ b/src/alfagok/__init__.py @@ -0,0 +1 @@ +"""alfagok package.""" diff --git a/src/alfagok/main.py b/src/alfagok/main.py new file mode 100644 index 0000000..66b8a36 --- /dev/null +++ b/src/alfagok/main.py @@ -0,0 +1,23 @@ +from typing import Union + +from fastapi import FastAPI +from pydantic_settings import BaseSettings +from pydantic import FilePath + + +class Settings(BaseSettings): + word_list: FilePath + + +app = FastAPI() +settings = Settings() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: Union[str, None] = None): + return {"item_id": item_id, "q": q} diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..09b8ad8 --- /dev/null +++ b/tox.ini @@ -0,0 +1,21 @@ +[flake8] +ignore = D203, W503 +exclude = + .git, + __pycache__, + docs/source/conf.py, + build, + dist, + example_config/gunicorn_webhaak_conf.py, + example_config/rq_settings.example.py, + example_config/settings.py, +max-line-length = 120 +max-complexity = 10 + +[pycodestyle] +max_line_length = 120 +ignore = E501, W503 + +[isort] +line_length = 120 +multi_line_output = 3 diff --git a/wordlist/create_list.py b/wordlist/create_list.py new file mode 100644 index 0000000..1e0c56d --- /dev/null +++ b/wordlist/create_list.py @@ -0,0 +1,36 @@ +import random + +MIN_LENGTH = 5 +MAX_LENGTH = 10 + +NUMBER_DAYS = 5 * 365 + +with open('basiswoorden-gekeurd.txt', 'r', encoding='utf-8') as wordfile: + all_words = wordfile.readlines() + print(f'original list contains {len(all_words)} words') + + result_list = [] + for word in all_words: + word = word.strip() + if word.isalpha() and word.lower() == word and len(word) > MIN_LENGTH and len(word) <= MAX_LENGTH: + result_list.append(f'{word}\n') + + # print(result_list) + print(f'words filtered: {len(result_list)} with length > {MIN_LENGTH} and <= {MAX_LENGTH}') + + with open('filtered.txt', 'w', encoding='utf-8') as f: + f.writelines(result_list) + + selection_list = [] + + # Randomly select words for each day + while len(selection_list) < NUMBER_DAYS: + # Use index - 1 because lists start at index 0 + word_index = random.randrange(0, len(result_list) - 1) + selection_list.append(result_list[word_index]) + + # Save the result + with open('word_of_the_day.txt', 'w', encoding='utf-8') as f: + f.writelines(selection_list) + + print(f'done writing {len(selection_list)} random words, enjoy!')