RTs via RE's
regextweet, simple create an account, register an app, and copy these the keys found on http://dev.twitter.com/apps into a text file named
api.txt in the project's root directory, i.e:
consumer_key consumer_secret access_token access_token_secret
regextweet we can quickly follow a list, filter information of interest, and retweet it. Here's the usage template:
python regextweet.py --u user_name --l list_name --o list_owner --r "regex" --a api.txt --h handles.txt
--udefines the user name of the retweetbot
--ldefines the name of the list to follow and filter,
--ris the quoted regular expression to query the text with.
--ois the user name of the person who owns the list (optional; see below)
--ais the filepath to the textfile with your api credentials (default = "api.txt")
--his the filepath to the textfile with the list of twitter users to follow (optional; regextweet will not bother with this if
--ois provided, and will just follow the list
--lowned by user
--o. If neither
--hdefaults to "header.txt" . If this is the case and "header.txt" does not exist, the program will break')
python regextweet.py --u yourrepsonguns --l members-of-congress --o cspan --r "(gun)"
However, this only ran the retweet bot once.
To run it on a continual basis, we created a cron job by writing:
And inserting this line of text at the top of our crontab settings.
*/5 * * * * /usr/bin/python /home/ec2-user/regextweet.py python regextweet.py --u yourrepsonguns --l members-of-congress --o cspan --r "(gun)"
Here, the five *'s correspond to minutes, hours, days, months, years, respectively. Our setting runs the job every 5 minutes forever.
Make your own tweetbot
If you want to try out
regextweet.py simply download the repository, navigate to the extracted folder and customize
handles.txt according to your preferences. Before running
regextweet.py, make sure to run:
sudo pip install tweepy oauth2 requests
which should cover the necessary dependencies.
Now you can create an account called "biebergoestowashington" and retweet every time a representative mentions justin bieber by simply typing:
python regextweet.py --u biebergoestowashington --l members-of-congress --o cspan --r "(bieber)"
regextweet.py only works for twitter feeds, the same idea could scale to facebook pages, rss feeds, and even CSPAN by using opened-captions. Help me build something better!