From 2c67baf4256ee688f16128ab336bca695ad89416 Mon Sep 17 00:00:00 2001 From: Yutu Date: Thu, 4 Jul 2024 05:00:33 -0400 Subject: [PATCH] init --- .gitignore | 162 +++++++++++++++++++++++++++++++++++++++ LICENSE.txt | 9 +++ README.md | 21 +++++ pyproject.toml | 157 +++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + src/checkin/__about__.py | 4 + src/checkin/__init__.py | 3 + src/checkin/checkin.py | 38 +++++++++ tests/__init__.py | 3 + 9 files changed, 398 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 src/checkin/__about__.py create mode 100644 src/checkin/__init__.py create mode 100644 src/checkin/checkin.py create mode 100644 tests/__init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bbd77a --- /dev/null +++ b/.gitignore @@ -0,0 +1,162 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# 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/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +config.ini diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..ec4a307 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023-present U.N. Owen + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a2813f --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# checkin + +[![PyPI - Version](https://img.shields.io/pypi/v/checkin.svg)](https://pypi.org/project/checkin) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/checkin.svg)](https://pypi.org/project/checkin) + +----- + +**Table of Contents** + +- [Installation](#installation) +- [License](#license) + +## Installation + +```console +pip install checkin +``` + +## License + +`checkin` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..40bbb11 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,157 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "checkin" +dynamic = ["version"] +description = '' +readme = "README.md" +requires-python = ">=3.7" +license = "MIT" +keywords = [] +authors = [ + { name = "U.N. Owen", email = "void@some.where" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "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 :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = [] + +[project.urls] +Documentation = "https://github.com/unknown/checkin#readme" +Issues = "https://github.com/unknown/checkin/issues" +Source = "https://github.com/unknown/checkin" + +[tool.hatch.version] +path = "src/checkin/__about__.py" + +[tool.hatch.envs.default] +dependencies = [ + "coverage[toml]>=6.5", + "pytest", +] +[tool.hatch.envs.default.scripts] +test = "pytest {args:tests}" +test-cov = "coverage run -m pytest {args:tests}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] + +[[tool.hatch.envs.all.matrix]] +python = ["3.7", "3.8", "3.9", "3.10", "3.11"] + +[tool.hatch.envs.lint] +detached = true +dependencies = [ + "black>=23.1.0", + "mypy>=1.0.0", + "ruff>=0.0.243", +] +[tool.hatch.envs.lint.scripts] +typing = "mypy --install-types --non-interactive {args:src/checkin tests}" +style = [ + "ruff {args:.}", + "black --check --diff {args:.}", +] +fmt = [ + "black {args:.}", + "ruff --fix {args:.}", + "style", +] +all = [ + "style", + "typing", +] + +[tool.black] +target-version = ["py37"] +line-length = 120 +skip-string-normalization = true + +[tool.ruff] +target-version = "py37" +line-length = 120 +select = [ + "A", + "ARG", + "B", + "C", + "DTZ", + "E", + "EM", + "F", + "FBT", + "I", + "ICN", + "ISC", + "N", + "PLC", + "PLE", + "PLR", + "PLW", + "Q", + "RUF", + "S", + "T", + "TID", + "UP", + "W", + "YTT", +] +ignore = [ + # Allow non-abstract empty methods in abstract base classes + "B027", + # Allow boolean positional values in function calls, like `dict.get(... True)` + "FBT003", + # Ignore checks for possible passwords + "S105", "S106", "S107", + # Ignore complexity + "C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915", +] +unfixable = [ + # Don't touch unused imports + "F401", +] + +[tool.ruff.isort] +known-first-party = ["checkin"] + +[tool.ruff.flake8-tidy-imports] +ban-relative-imports = "all" + +[tool.ruff.per-file-ignores] +# Tests can use magic values, assertions, and relative imports +"tests/**/*" = ["PLR2004", "S101", "TID252"] + +[tool.coverage.run] +source_pkgs = ["checkin", "tests"] +branch = true +parallel = true +omit = [ + "src/checkin/__about__.py", +] + +[tool.coverage.paths] +checkin = ["src/checkin", "*/checkin/src/checkin"] +tests = ["tests", "*/checkin/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/checkin/__about__.py b/src/checkin/__about__.py new file mode 100644 index 0000000..ddfcbd8 --- /dev/null +++ b/src/checkin/__about__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023-present U.N. Owen +# +# SPDX-License-Identifier: MIT +__version__ = "0.0.1" diff --git a/src/checkin/__init__.py b/src/checkin/__init__.py new file mode 100644 index 0000000..cd85244 --- /dev/null +++ b/src/checkin/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2023-present U.N. Owen +# +# SPDX-License-Identifier: MIT diff --git a/src/checkin/checkin.py b/src/checkin/checkin.py new file mode 100644 index 0000000..d72b449 --- /dev/null +++ b/src/checkin/checkin.py @@ -0,0 +1,38 @@ +import requests +import urllib.parse as urlparse +from urllib.parse import parse_qs +from configparser import ConfigParser + +config = ConfigParser() +config.read("config.ini") + +act_url = "https://bbs-api-os.hoyolab.com/community/painter/wapi/circle/info" +luna_url = "https://sg-public-api.hoyolab.com/event/luna/os/sign" +mani_url = "https://sg-public-api.hoyolab.com/event/mani/sign" +sol_url = "https://sg-hk4e-api.hoyolab.com/event/sol/sign" +api_urls = [luna_url, mani_url, sol_url] + +payload = "" +act_headers = {"x-rpc-client_type": "4"} +cookie = { + "Cookie": f"ltoken={config['DEFAULT']['ltoken']}; ltuid={config['DEFAULT']['ltuid']}", +} + +response = requests.request("GET", act_url, data=payload, headers=act_headers) +if response.status_code != 200: + exit(1) +for game in response.json()["data"]["game_list"]: + checkin_item = None + for tool in game["tool"]: + if "check" in tool["name"].lower() and "in" in tool["name"].lower(): + checkin_item = tool + if checkin_item is None: + continue + params = urlparse.urlparse(checkin_item["web_path"]) + act = parse_qs(params.query)["act_id"][0] + payload = '{"act_id": "' + act + '"}' + print(game["name"]) + for url in api_urls: + response = requests.request("POST", url, data=payload, headers=cookie) + print(url + ": " + response.json()["message"]) +exit(0) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..cd85244 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2023-present U.N. Owen +# +# SPDX-License-Identifier: MIT