2.6 KiB
2.6 KiB
python3 script for reading corona case numbers for Marburg-Biedenkopf area. Sends data to a telegram channel, if you set a bot_token and chat_id.
dependencies
pip install -r requirements.txt
invocation
$ python mrcovid19bot.py
You can easily convert the output to CSV format:
$ python mrcovid19bot.py`| tr '\t' ','
To only see the latest available numbers:
$ python mrcovid19bot.py`| head -n2
To mit the headers:
$ python mrcovid19bot.py`| tail -n+2
The above can obviously be combined to your liking for thing like graph plotting.
example output
[fix@radon mrcovid19bot]$ python mrcovid19bot.py | head -n 5
date infected stationary recovered passed incidence
16.10.2020 746 6 540 5 59.2
15.10.2020 704 7 522 5 54.0
14.10.2020 658 7 512 5 41.4
13.10.2020 634 9 504 5 43.8
posting to telegram
The bot can post to telegram channels, chats and groups.
HowTo:
- create a Telegram bot token at the BotFather
- create a new channel or find out your target chat's chat_id
- set them as environment variables:
export CHAT_ID='@mrcovid19updates'
export BOT_TOKEN='XXXXXXXXXXX:YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
- run the script as mentioned in invocation
systemd integration
This script can run via a systemd-timer, especially as (non-root) user-units.
setup
- fill in the
Environmentvariables inmrcovid19bot.servicewith yourBOT_TOKENandCHAT_ID. These values will be passed to the script. - copy the files
mrcovid19bot.serviceandmrcovid19bot.timerto the directory that holds the user units, for Arch Linux this is${HOME}/.config/systemd/user. - run
systemctl --user daemon-reloadand enable the timer:systemctl --user start mrcovid19bot.timer. The provided timer file will start the matching service file once a day. - you might want to enable lingering (else the timer/service gets killed if you have no more active systemd-slices, aka you have no active login):
loginctl enable-linger ${USER}
You can check the timer status like this:
$ systemctl --user status mrcovid19bot.timer
● mrcovid19bot.timer - mrcovid19bot timer
Loaded: loaded (/home/user/.config/systemd/user/mrcovid19bot.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Fri 2020-10-16 22:18:35 CEST; 3s ago
Trigger: Sat 2020-10-17 22:14:04 CEST; 23h left
Triggers: ● mrcovid19bot.service
Okt 16 22:18:35 radon systemd[580]: Started mrcovid19bot timer.