A bot that follows the traffic reports of Guatemala City on Twitter, inspired by @RealPressSecBot, @PressSecBotPlus and @guatebot. Follow TrafficBotGT on Twitter as @TrafficBotGT
###Contents
Inspired by @realPressSecBot, @PressSecBotPlus and @guatebot. TrafficBotGT is a Python based Twitter bot that will reformat tweets by a specified hashtag into a press release image and publishes to Twitter. Optimized for python3.
- Python3
- Use of the Twitter Streaming API for real-time updates
- Follow specific words and hashtags
- Clickable links
- Inline Twitter full name expansion
- Quoted tweet formatting
- A Twitter API key, and an account from which to publish tweets
- Python 3 (compatible with Python 2.7)
- python-twitter
- wkhtmltoimage, part of wkhtmltopdf
- Jinja2
- Pillow
- Install the requirements:
- Download wkhtmltopdf, or install from your package manager
pip install python-twitter Jinja2 Pillow
(easy_install
also works)pip3 install python-twitter Jinja2 Pillow
(for python3)
- Download the source and unzip it (or clone the repository locally)
- Set up a Twitter app
- Follow the Python-twitter instructions to create an app and get your API keys and access tokens
- If you want to register your app with a different account than the one your bot will tweet from, use the
get_access_token.py
script to get the access tokens for the bot's account
- Change the values in
twitter_token.conf
and configure per the Configuration section
In the settings
section of twitter_token.conf
:
- Enter the words or hashtags you wish to create releases for. (
words_to_track = #TraficoGT,#TransitoGT
) - Enter the text you wish to prefix each tweet with (no quotes necessary); to have no text, delete the placeholder or the whole line (
message = TWEET_STATUS_TEXT_HERE
)
In the twitter_api
section, enter your Twitter API credentials as labelled.
Run TrafficBotGT with python3 TrafficBot.py
, or first mark it as executable with chmod +x TrafficBot.py
, then run ./TrafficBot.py
.
When run, TrafficBot wait for any tweets that contains the words to track. It will then check real time for new tweets, until you quit.
As TrafficBotGT is intended to publish an ongoing stream of tweets, it is recommended that you run it as a daemon process. The best way of doing this will vary by OS. Systemd for Ubuntu, Launchd for MacOS, or rc.d for FreeBSD are suggested. Be careful to set the working directory to wherever TrafficBot.py
is, as it expects other resources to be installed there.
Alternatively, you can run it as a background process using screen
or similar.
PressSecBotPlus is Copyright © 2017 by Rob Mathers and licensed under the MIT license. You may do what you like with the software, but must include the license and copyright notice.
guatebot is Copyright © 2017 by valerybriz and licensed under the GNU General Public License v3.0. You may do what you like with the software, but must include the license and copyright notice.
jQueryEmoji is used in this code and is Copyright (c) by Rodrigo Polo and licensed under the MIT License.