瀏覽代碼

feat: add bot's business-logic files

First commit of alpha version arxiv vanity bot.
Add some actions and pre-commit-hook files.
Actions and pre-commit not working yet.
metya 4 年之前
父節點
當前提交
01526d03b4

+ 22 - 0
.github-not_work_yet/dependabot.yaml

@@ -0,0 +1,22 @@
+# Configuration: https://dependabot.com/docs/config-file/
+# Docs: https://docs.github.com/en/github/administering-a-repository/keeping-your-dependencies-updated-automatically
+
+version: 2
+
+updates:
+  - package-ecosystem: "pip"
+    directory: "/"
+    schedule:
+      interval: "daily"
+    allow:
+      - dependency-type: "all"
+    commit-message:
+      prefix: ":arrow_up:"
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "daily"
+    allow:
+      - dependency-type: "all"
+    commit-message:
+      prefix: ":arrow_up:" v

+ 22 - 0
.github-not_work_yet/workflows/bumpversion.yml

@@ -0,0 +1,22 @@
+name: Bump version
+
+on:
+  push:
+    branches:
+      - master
+
+jobs:
+  bump-version:
+    if: "!startsWith(github.event.head_commit.message, 'bump:')"
+    runs-on: ubuntu-latest
+    name: "Bump version and create changelog with commitizen"
+    steps:
+      - name: Check out
+        uses: actions/checkout@v2
+        with:
+          token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
+          fetch-depth: 0
+      - name: Create bump and changelog
+        uses: commitizen-tools/commitizen-action@master
+        with:
+          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

+ 27 - 0
.github-not_work_yet/workflows/pythonpublish.yaml

@@ -0,0 +1,27 @@
+# name: Upload Python Package
+
+# on:
+#   push:
+#     tags:
+#       - '*' # Will trigger for every tag, alternative: 'v*'
+
+# jobs:
+#   deploy:
+#     runs-on: ubuntu-latest
+#     steps:
+#     - uses: actions/checkout@v1
+#     - name: Set up Python
+#       uses: actions/setup-python@v1
+#       with:
+#         python-version: '3.x'
+#     - name: Install dependencies
+#       run: |
+#         python -m pip install --pre -U poetry
+#         poetry --version
+#         poetry install
+#     - name: Build and publish
+#       env:
+#         PYPI_USERNAME: __token__
+#         PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
+#       run: |
+#         ./scripts/publish

+ 132 - 0
.gitignore

@@ -0,0 +1,132 @@
+# 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/
+pip-wheel-metadata/
+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/
+
+# 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
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.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
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__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
+
+# VSCode
+.vscode
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/

+ 7 - 0
.pre-commit-config.yaml

@@ -0,0 +1,7 @@
+repos:
+- hooks:
+  - id: commitizen
+    stages:
+    - commit-msg
+  repo: https://github.com/commitizen-tools/commitizen
+  rev: v2.4.1

+ 2 - 0
config.py

@@ -0,0 +1,2 @@
+
+API_TOKEN = 'token'

二進制
pipchillreq.txt


+ 30 - 0
pyproject.toml

@@ -0,0 +1,30 @@
+[tool.poetry]
+name = "vanity-bot"
+version = "0.1.0"
+description = "Telegram bot that replace arxiv.org links with mobile responsive and fancy arxiv-vanity.com links with builtin snippets to telegram chats."
+authors = ["metya <metya.tm@gmail.com>"]
+
+[tool.poetry.dependencies]
+python = "^3.9"
+aiogram = "^2.10.1"
+logzero = "^1.5.0"
+cchardet = "^2.1.6"
+ujson = "^4.0.1"
+aiohttp = {extras = ["speedups"], version = "^3.6.3"}
+multidict = "^5.0.0"
+aiodns = "^2.0.0"
+brotlipy = "^0.7.0"
+
+[tool.poetry.dev-dependencies]
+pip-chill = "^1.0.0"
+pipreqs = "^0.4.10"
+commitizen = "^2.4.1"
+pre-commit = "^2.7.1"
+
+[tool.commitizen]
+name = "cz_conventional_commits"
+version = "0.0.1"
+tag_format = "$version"
+[build-system]
+requires = ["poetry-core>=1.0.0"]
+build-backend = "poetry.core.masonry.api"

+ 47 - 0
vanitybot.py

@@ -0,0 +1,47 @@
+from aiogram.types import message
+from aiogram.types.message import Message
+from logzero import logger
+import logging
+
+from aiogram import Bot, Dispatcher, executor, types
+from config import API_TOKEN
+
+# Configure logging
+logging.basicConfig(level=logging.INFO)
+
+# Initialize bot and dispatcher
+bot = Bot(token=API_TOKEN)
+dp = Dispatcher(bot)
+
+@dp.message_handler(commands=['start'])
+async def process_start_command(message: types.Message):
+    await message.reply("Hello!\n\n\
+Send me a link paper from arxiv.org and \
+I'll send you back arxiv-vanity.com link with paper!\n\
+Or add me to chat and I'll be watching the arxiv link and \
+reply to them with fancy axiv-vanity links.")
+
+
+@dp.message_handler(commands=['help'])
+async def process_help_command(message: types.Message):
+    await message.reply("Напиши мне что-нибудь, и я отпрпавлю этот текст тебе в ответ!")
+
+
+# @dp.message_handler()
+# async def echo_message(message: types.Message):
+#     await bot.send_message(message.from_user.id, message.text)
+
+@dp.message_handler(regexp='arxiv.org/\s*([^\s]*)')
+async def cats(message: types.Message):
+    id_paper = (message.text
+                .replace('/abs', '')
+                .replace('/pdf', '')
+                .replace('.pdf', '')
+                .split('/')[-1]
+                .split(' ')[0])
+    await message.reply(f'https://arxiv-vanity.com/papers/{id_paper}')
+    # await bot.send_message(message.from_user.id, message.text)
+
+
+if __name__ == "__main__":
+    executor.start_polling(dp, skip_updates=True)