A Telegram bot to inform you of birthdays, holidays, events, etc.
Moving away from Facebook, I needed a better way to keep track of people's birthdays, anniversaries, holidays, or miscellaneous events. I've tried using a calendar app, but the notifications just blended together with calendar notifications from my work calendar. So, I wanted a way to notify myself of important things in a way I'd actually pay attention to.
You'll get a push notification:
- 14 days before
- 7 days before
- 1 days before
- The day of
- Python3
- Telegram account
python3 -m venv venv
Windows:
source venv/Scripts/activate
Mac / Linux
source venv/bin/activate
pip install -r requirements.txt
I've used this guide to create a Telegram bot.
-
Message
@BotFatherthrough the Telegram client`/start` -
Create a bot
`/newbot` -
Name the bot
`somebotname` -
Give it a user name
`somebotname_bot`
You'll be given the API key at this point. The key, and the _bot name will be used in the .env file
- Optional give it a picture
Message @userinfobot
Just starting a conversation with the bot will return your UserID
Find your bot by searching for @somebotname_bot and hit 'message'. You should see the following happen.
/start
This lets the bot now start communicating with you.
The sample file .env_sample is provided to get you started. Essentially:
TELEGRAM_TOKEN=<paste-token-here>
USER_ID=<paste-id-here>
Rename to .env and save.
The sample file sample_dates.json is provided to get you started.
The overall thought is that the dictionary is iterated through by the script, and each top-level key is another dictionary of dates associated with that key. While not designed to be fully extensible, (ie, making custom categories) this shouldn't be too hard if a new category is desired.
Date format is yyyy-mm-dd or mm-dd. Leading zeroes for months and days are ok.
I find it convenient to let the script run automatically on its own without my intervention. I use a home server which I always keep on to run this program daily. But a laptop or other device could be used as well, although a different configuration in the Chron or Windows Task Scheduler would be needed to run the script on power up or ensure it will run even if it missed the designated time.
The provided shellscript telegramnotifier.sh will need to be updated with the correct paths. The first argument is for the location for the python installation.
A tool like crontab guru is helpful for visualizing the crontab syntax
As Crontab doesn't natively run on Windows, the Task Scheduler can be used. The shell script isn't really needed here. You can run the virtual environment python.exe and telegramnotifier.py script all at once.
I've followed this guide to schedule python tasks.
- Create the task
- The exectubale is
path/to/the/venv/Scripts/python.exefor windows - The optional argument the path/to/the/telegramnotifier/telegramnotifier.py
- The exectubale is