Skip to content

App to pull down tweet activity from specific accounts and send to Telegram via a bot

License

Notifications You must be signed in to change notification settings

dmuth/twitter-account-metrics-bot

Repository files navigation

Twitter Account Metrics Bot

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.

Requirements

Screenshots

AskAmex Tweets for 7 days AskAmex Tweets for 3 days AskAmex Tweets for 6 hours

Setup

  • 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 to tweets.db, which is a SQLite database.
    • Run ./bin/run.sh 1-export-to-json to export all tweets to tweets.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 the tweets.db file to AWS S3.
  • Normal usage:
    • Run docker-compose up -d and tweets will start being downloaded with stats being written to the Telegram Channel of your user.

Development

  • 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

FAQ

How do I get Telegram Group/Chat IDs?

From https://stackoverflow.com/a/45577773/196073:

Architecture: Why A Single Docker Container?

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. :-)

Credits

  • 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

Author

Myself, Douglas Muth. Ways you can get in touch with me:

About

App to pull down tweet activity from specific accounts and send to Telegram via a bot

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published