An app to get metrics from Twitter accounts and report them to Telegram via a bot.
This is useful for monitoring activity on organization social media accounts.
- Docker
- Go to https://developer.twitter.com/ and create an App. Note your Consumer API Key and Secret Key.
- Clone this repo to your machine
- Run
./bin/run.sh 0-get-credentials
to configure the app. You'll need your Twiter API data, and (optionally) AWS and Telegram credentials as well.- AWS credentials can be obtained from the AWS console and is beyond the scope of this document.
- Telegram credentials can be obtained from messaging BotFather and following the instructions.
- Manual usage:
- Run
./bin/run.sh 1-fetch-tweets
to fetch tweets and store them totweets.db
, which is a SQLite database. - Run
./bin/run.sh 1-export-to-json
to export all tweets totweets.json
. - Run
./bin/run.sh 2-telegram-bot
to start reporting tweet stats to Telegram - Run
./bin/run.sh 2-backup-tweets
to start a script that periodically backs up thetweets.db
file to AWS S3.
- Run
- Normal usage:
- Run
docker-compose up -d
and tweets will start being downloaded with stats being written to the Telegram Channel of your user.
- Run
- To work on a script interactively:
./bin/dev.sh
- This will launch the container with an interactive shell.- Scripts live in
/mnt/bin/
on this container.
- To download the latest backup:
./bin/aws/download-latest-backup
From https://stackoverflow.com/a/45577773/196073:
- Go to your group in the web interface and grab the link. e.g. https://web.telegram.org/#/im?p=g154513121
- Copy That number after g and put a (-) Before That. e.g. -154513121
- Send Your Message to group. e.g.
bot.send_message(-154513121, "Hi")
In a past version of this app, I used to have 5 different development and run scripts spread across 4 different Docker containers, and the end result is that the bin/
directory got really unruly, holding 30 files in total, many of them very nearly identical to multiple other files.
I made the conscious decision to merge 4 slightly different Dockerfiles together into a single Dockerfile. While the single image is a bit on the large side (347 MB), I reduced the total number of files in bin/
from 30 down to 13 and made my overall development and usage process simpler than it was before. In fact, with the exception of this particular section, this entire README got shorter sa a result. I think I made a good decision here. :-)
- Twython - The Twitter client for Python, this made using Twitter's API a breeze.
- SQLite - Used for data storage.
- SQLAlchemy - This is my first project with SQLAlchemy, and it made tasks such as database schema maintenance and interacting with the database way easier to do!
- python-telegram-bot - I use this module for connecting to Telegram, and it too makes my life much easier.
- Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
Myself, Douglas Muth. Ways you can get in touch with me:
- My website
- ...or just file a bug on this repo!