A Telegram bot (based on Pyrogram) to manage affairs of the St. Thomas Orthodox Syrian Cathedral (STOSC), Singapore.
Setup virtual environment
python -m venv .venv
Activate (on Windows):
.venv\Scripts\activate.bat
On Linux:
Change config.ini
for server.
source .venv/bin/activate
nohup python3 run_stoscbot.py &
Dependencies
pip install -r requirements.txt
Upgrade dependencies, test locally and then freeze to requirements_pro.txt
pip install --upgrade pip
pip install --upgrade -r requirements.txt
pip freeze > requirements_pro.txt
Tests
Ensure pytest
and pytest-asyncio
is installed so that VSCode and find tests. Run the below command to run the tests.
pytest --cov=./ --cov-report=xml
coverage report
We use GitHub Actions to deploy, but the basic deploy steps are lsited below
Deploy on a VM
- Update server timezone to local timezone
- Do not re-use a session file when deploying to a new instance. On a new isntance, delete any existing
.session
file and generate a new session file. - Keep the
.env
and.session
files in a..\credentials\
directory. The deployment scripts will copy these files to the correct location. - Copy the Google API keys to
~/.config/gspread/service_account.json
. On Windows, it's atC:\Users\xxx\AppData\Roaming\gspread\
- Subsequently run headless as
nohup python3 run_stoscbot.py &
- Make better decorators. See https://youtu.be/QH5fw9kxDQA?t=843
- Add arguments to decorators(https://youtu.be/QH5fw9kxDQA?t=1164)
- Define Default Values in Dictionaries With
.get()
and.setdefault()
- In iterating over long lists, use generators
- Check if using
logger
orloggers
class - How to make a sync function to async
- Split the GitHub Actions Job
Build_Lint_Test_Coverage
to two jobs:Build_Lint
andTest_Coverage
. Use cache - Change to dictionary
_get
e.g.income = _item.get('income', 0.0)