Fork of tommeagher/heroku_ebooks. Fixed issue #6 (although possibly in an awkward/unintelligent fashion [see above warning]). Primarily a refactor of the ebooks.py source to move more functionality into more methods (easier for me to understand and modify that way). Changed a couple of things I didn't understand and it doesn't appear to have broken, so we'll call it a win until I find out otherwise.
Renamed from heroku_ebooks to kyofu_ebooks since I don't use Heroku; works fine scheduled via a crontab.
This is a basic Python port of @harrisj's iron_ebooks Ruby script. Using Heroku's scheduler, you can post to an _ebooks Twitter account based on the corpus of an existing Twitter at pseudorandom intervals. Currently, it is the magic behind @adriennelaf_ebx and @stevebuttry_ebx.
local_settings_example.pyfile and name it
local_settings.py, be sure to add the handle of the Twitter user you want your _ebooks account to be based on. To make your tweets go live, change the
heroku createto generate the _ebooks Python app on the platform that you can schedule.
pip installof which is handled by Heroku automatically.
git commit -am 'updated the local_settings.py'
git push heroku master
heroku run worker. You should either get a response that says "3, no, sorry, not this time" or a message with the body of your post. If you get the latter, check your _ebooks Twitter account to see if it worked.
heroku addons:add scheduler:standard
heroku addons:open scheduler. This will open up a browser window where you can adjust the time interval for the script to run. I recommend setting it at one hour.
There are several parameters that control the behavior of the bot. You can adjust them by setting them in your
ODDS = 8
The bot does not run on every invocation. It runs in a pseudorandom fashion. At the beginning of each time the script fires,
guess = random.choice(range(ODDS)). If
guess == 0, then it proceeds. If your
ODDS = 8, it should run one out of every 8 times, more or less. You can override it to make it more or less frequent. To make it run every time, you can set it to 0.
By default, the bot ignores any tweets with URLs in them because those might just be headlines for articles and not text you've written.
ORDER = 2
The ORDER variable represents the Markov index, which is a measure of associativity in the generated Markov chains. According to @harrisj, and I'll take his word for it, 1 is generally more incoherent and 3 is more lucid.
If you want to test the script or to debug the tweet generation, you can skip the random number generation and not publish the resulting tweets to Twitter.
First, adjust the
DEBUG variable in
DEBUG = True
After that, commit the change and
git push heroku master. Then run the command
heroku run worker on the command line and watch what happens.
If you want to avoid hitting the Twitter API and instead want to use a static text file, you can do that. First, create a text file containing a Python list of quote-wrapped tweets. Then set the
STATIC_TEST variable to
True. Finally, specify the name of text file using the
TEST_SOURCE variable in
As I said, this is based almost entirely on @harrisj's iron_ebooks. He created it in Ruby, and I wanted to port it to Python. All the credit goes to him. As a result, all of the blame for clunky implementation in Python fall on me. If you see ways to improve the code, please fork it and send a pull request, or file an issue for me and I'll address it.