Преглед изворни кода

🔧 refactor: clean up everything with folder structures

to good looking repository and easy to navigating
metya пре 2 година
родитељ
комит
6c96eee6fe
18 измењених фајлова са 30 додато и 22 уклоњено
  1. 1 0
      .dockerignore
  2. 1 0
      .github/workflows/deploy.yml
  3. 2 1
      .gitignore
  4. 1 3
      CHANGELOG.md
  5. 8 3
      README.md
  6. BIN
      assets/bot.png
  7. 0 0
      conda/develop.yaml
  8. 0 0
      db/papers.db
  9. 1 1
      docker/Dockerfile
  10. 3 1
      docker/compose.yaml
  11. 1 1
      scripts/backup_db.sh
  12. 0 0
      scripts/script.exp
  13. 1 1
      src/config.py
  14. 3 3
      src/db.py
  15. 2 2
      src/dialog.py
  16. 1 1
      src/progress.py
  17. 1 1
      src/summarize.py
  18. 4 4
      vanitybot.py

+ 1 - 0
.dockerignore

@@ -9,3 +9,4 @@ __pycache__
 .mypy_cache
 js.js
 paper.json
+misc

+ 1 - 0
.github/workflows/deploy.yml

@@ -24,6 +24,7 @@ jobs:
           ssh_private_key: ${{ secrets.PRIVATE_KEY }}
           ssh_public_key: ${{ secrets.PUBLIC_KEY }}
           deployment_mode: docker-compose
+          stack_file_name: docker/compose.yaml
           args: up -d --force-recreate --build
           docker_prune: "true"
           pull_images_first: "false"

+ 2 - 1
.gitignore

@@ -144,4 +144,5 @@ test*
 *.log
 geckodriver
 js.js
-paper.json
+paper.json
+misc

+ 1 - 3
CHANGELOG.md

@@ -1,6 +1,4 @@
-## 1.0.2 (2023-02-28)
-
-## 1.0.1 (2023-02-27)
+## 1.0.6 (2023-02-28)
 
 ### Fix
 

+ 8 - 3
README.md

@@ -2,7 +2,12 @@
 
 Telegram for some reason doesn't show snippets for links from arxiv.org site. This bot created to get work around of this problem. It is useful to having this bot in chats where you can share links from arxiv and bot will replying on that messages with some kind of snippets with title and description of paper and link to mobile friendly service for arxiv papers - arxiv-vanity.com
 
-Ready to use bot: t.me/arxiv_vanity_bot
+Also there is functionality of get summary of a paper with short highlights and findings. It is useful to get familiar with main findings of a paper and decide to read or not :)
+
+Ready to use bot: https://t.me/arxiv_vanity_bot
+
+## TODO
+Sometime I implement the functionality of getting Figures from a paper, because pictures is very important to understand what's going on :)
 
 ## Installation
 
@@ -22,7 +27,7 @@ And after that just
 docker compose up -d
 ```
 
-or use enviroments variable with compose instead of token file
+or use environment variables with compose instead of token file
 
 ```bash
 docker-compose run -d -e API_TOKEN=your_bot_token bot
@@ -30,7 +35,7 @@ docker-compose run -d -e API_TOKEN=your_bot_token bot
 
 ## Usage
 
-Add your bot in chat where you disscuss arxiv papers and enjoy. Or use my bot t.me/arxiv_vanity_bot
+Add your bot in chat where you discuss arxiv papers and enjoy. Or use my bot https://t.me/arxiv_vanity_bot
 
 ## Illustration
 


+ 0 - 0
develop.yml → conda/develop.yaml


+ 0 - 0
papers.db → db/papers.db


+ 1 - 1
Dockerfile → docker/Dockerfile

@@ -15,7 +15,7 @@ ADD requirements.txt /app
 RUN pip install --no-cache-dir -r requirements.txt
 RUN apk del .build-deps
 
-RUN echo "0 0 * * 1 /bin/sh /app/backup_db.sh" >> /var/spool/cron/crontabs/root
+RUN echo "0 0 * * 1 /bin/sh /app/scripts/backup_db.sh" >> /var/spool/cron/crontabs/root
 
 RUN git config --global user.name "metya"
 RUN git config --global user.email "metya.tm@gmail.com"

+ 3 - 1
docker-compose.yaml → docker/compose.yaml

@@ -1,7 +1,9 @@
 version: "3.7"
 services:
   bot:
-    build: .
+    build:
+      context: ..
+      dockerfile: docker/Dockerfile
     image: metya/vanity_bot
     container_name: vanity_bot
     environment:

+ 1 - 1
backup_db.sh → scripts/backup_db.sh

@@ -1,4 +1,4 @@
 cd /app
 git add papers.db
 git commit -m "backup papers.db" --no-verify
-expect script.exp ${GITHUB_TOKEN}
+expect scripts/script.exp ${GITHUB_TOKEN}

+ 0 - 0
script.exp → scripts/script.exp


+ 1 - 1
config.py → src/config.py

@@ -1,7 +1,7 @@
 from os import getenv
 from dotenv import dotenv_values
 
-if env_var := dotenv_values('token'):
+if env_var := dotenv_values('misc/token'):
     API_TOKEN = env_var["API_TOKEN"]
 else:
     API_TOKEN = getenv("API_TOKEN")

+ 3 - 3
db.py → src/db.py

@@ -5,11 +5,11 @@ from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession as _AsyncSe
 from sqlalchemy.orm import selectinload
 
 
-async_sqlite_url = "sqlite+aiosqlite:///papers.db"
+async_sqlite_url = "sqlite+aiosqlite:///db/papers.db"
 echo = False
 
 async_engine = create_async_engine(async_sqlite_url, echo=echo)
-engine = create_engine("sqlite:///papers.db", echo=echo)
+engine = create_engine("sqlite:///db/papers.db", echo=echo)
 
 
 # models
@@ -147,7 +147,7 @@ async def add_or_update_paper(id_:str, paper: dict, async_engine = async_engine)
 
 if __name__ == "__main__":
     import json
-    with open("paper.json", 'r') as file:
+    with open("misc/paper.json", 'r') as file:
         paper = json.load(file)
     paper["title"] = paper["metadata"]["title"]
     paper["authors"] = paper["metadata"]["author"].split(",").strip()

+ 2 - 2
dialog.py → src/dialog.py

@@ -9,9 +9,9 @@ from aiogram_dialog.widgets.kbd import Radio
 from aiogram_dialog.widgets.text import Format
 from aiogram.types import ParseMode
 
-from summarize import get_summary
+from src.summarize import get_summary
 
-from progress import Bg, background
+from src.progress import Bg, background
 
 warn = "***Note, that it is an AI generated summary, and it may contain complete bullshit***"
 

+ 1 - 1
progress.py → src/progress.py

@@ -13,7 +13,7 @@ from aiogram_dialog.widgets.text import Const, Multi, Text
 
 from typing import Any
 
-from config import API_TOKEN
+from src.config import API_TOKEN
 
 
 class Processing(Text):

+ 1 - 1
summarize.py → src/summarize.py

@@ -6,7 +6,7 @@ from aiohttp import ClientSession
 from aiogram_dialog import DialogManager
 from typing import Any
 
-from db import add_authors_and_paper, add_or_update_paper, check_paper
+from src.db import add_authors_and_paper, add_or_update_paper, check_paper
 
 base_url = "https://engine.scholarcy.com/api/"
 extract_url = "metadata/extract"

+ 4 - 4
vanitybot.py

@@ -4,10 +4,10 @@ import asyncio
 from aiogram.contrib.fsm_storage.memory import MemoryStorage
 from aiogram import Bot, Dispatcher, executor, types
 from aiogram_dialog import DialogManager, DialogRegistry, StartMode
-from config import API_TOKEN
-from dialog import dialog, MySG
-from progress import bg_dialog
-from summarize import get_paper_desc
+from src.config import API_TOKEN
+from src.dialog import dialog, MySG
+from src.progress import bg_dialog
+from src.summarize import get_paper_desc
 
 # Initialize bot and dispatcher
 bot = Bot(token=API_TOKEN) # type: ignore