An open API service indexing awesome lists of open source software.

https://github.com/dmuth/twitter-account-metrics-bot

App to pull down tweet activity from specific accounts and send to Telegram via a bot
https://github.com/dmuth/twitter-account-metrics-bot

Last synced: about 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

# 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

- Docker
- Go to https://developer.twitter.com/ and create an App. Note your Consumer API Key and Secret Key.

## 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:
- 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")`

## 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:
- My website
- Twitter
- Facebook
- ...or just file a bug on this repo!