Personal telegram bot to interact between your Telegram account and your computer
Project description
pybliotecario
pybliotecario is a simple Telegram bot written en python. The goal of the program is to mantain an active connection between the computer in which the pybliotecario runs and your Telegram account.
Installing the pybliotecario
The pybliotecario can be installed as other python projects, using pip
pip install pybliotecario
o setuptools:
python3 setup.py install
When it is installed in this way, the name of the executable will be Hostname (i.e., the name of the computer in which it is running with the first letter capitalized). If you want to use a different name just modify the variable pybliotecario_name
inside setup.py
.
In order to link the program with a Telegram bot it is necessary to create a bot talking with Telegram's BotFather. The --init
option will guide you through the process.
pybliotecario --init
A small systemd_install.sh
script is shipped alongside the github version of the pybliotecario in order to daemonize it easily.
Configuration of the pybliotecario
All configuration options of the pybliotecario can be found in the file
$HOME/.pybliotecario.ini
This file will be automatically created (And most of the options filled) automatically by running --init
.
Extending the pybliotecario
The program aims to be 100% extensible, running any kind of action in two different modes:
- Command line: just call the command with the proper arguments. For instance, send a msg to your phone.
- Message command: write a command to the bot from telegram, so the bot can act on said command.
Adding new actions to each of the different modes is trivial, there are a small example for each case in the relevant files.
In order to add a new command to the bot you need to modify the file on_cmdline.py
(for command line arguments) or on_cmd_message.py
for commands sent from Telegram. The easiest course of action is to copy one of the components (in the components
folder you can see the different modules) and add your own actions. The simplest of them is probably components/ip_lookup.py
so have a look at it!
Command line:
In the file on_cmdline.py
add a new if condition. You can add your action there as python code. If you want to do something more complicated I suggest you create a new component (pull requests are welcome!)
Note: if you need new command line arguments (you surely do!) don't forget to add them to the end of argument_parser.py
!
Example: -i test.jpg, this will send the image named test.img to your defined Telegram chat
Message command:
These are command received by the bot in the form /command Do whatever
. In the file on_cmd_message.py
just add a new command to the if condition. The command definition will be defined in the variable tg_command
.
There you can just write the python code to perform the command or add a new component. All the information from the msg the bot just received will be included in the message_obj
variable. In particular the text will be message_obj.text
.
Example: if you send the command /ip, the bot will respond with the current ip of the machine it is running in.
Available cmd_line options:
- msg: sends msg to Telegram
- -i: sends a image to Telegram
- -f: sends a file to Telegram
- --arxiv_new: sends a msg to Telegram with the latest submissions to arxiv, filtered as you see fit (uses https://github.com/lukasschwab/arxiv.py as API)
- --weather: sends a msg to Telegram with the current weather and some information about the forecast (uses https://github.com/csparpa/pyowm as OpenWeatherMap API, which needs an API key)
- --check_repository: sends a msg to Telegram with the incoming changes to the repository
- --my_ip: send the ip of the bot to the defined telegram user
- --pid: Monitor a process by PID, run all other options after the process has finished.
Available commands
- /ip : tells you the IP where the bot is currently running
- /arxiv-query arxiv_id: returns information on the queried paper
- /arxiv-get arxiv_id: downloads the paper ands sends it to telegram
- /is_pid_alive pid_number/process_name: checks whether a given process is alive
- /kill_pid: kills the given process in the computer in which the bot is running
Some examples and ideas:
For instance, you can run the pybliotecario every morning at 7:15 a.m. to tell you what are the news in the arxiv today adding a cronjob:
15 07 * * mon-fri /home/pi/Telegram/pybliotecario/pybliotecario.py --arxiv_new
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pybliotecario-1.1.tar.gz
.
File metadata
- Download URL: pybliotecario-1.1.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea38507aaa7756aa67ad1fa5ded4903f6df5f4d5b92ec1e3f99a59dd399f335f |
|
MD5 | b2296e49c3ca83776f7bddb65bcb4899 |
|
BLAKE2b-256 | d1d8f7fb1462ec93d7fdde649a2bfbf7cfc608acf29142abb27d9233b117f562 |
File details
Details for the file pybliotecario-1.1-py3-none-any.whl
.
File metadata
- Download URL: pybliotecario-1.1-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c247e9468d21e11f12685e3813a126f712c83b7d60e9fab729fd4544468f0ebb |
|
MD5 | 1f24c6fb37fd37e7c313f8dd777413d6 |
|
BLAKE2b-256 | 457ad9518f11a657cfc93593d0849b9629cd6d200425604c588f930bdcf4f3de |