Skip to content

hugovk/randomsentencebot

Repository files navigation

randomsentencebot

Build Status Python: 3.6+ Code style: black

Tweet a random line from a text file. Use this to make your own Twitter bots.

For example, Six-Worder Bot is tweeting six-word stories picked at random from a text file of six-word sentences taken from the Project Gutenberg August 2003 CD. Think along the lines of "For Sale, Baby Shoes, Never Worn" (probably not by Ernest Hemingway). See the archive.

In @sixworderbot's case, the text file was generated using gutengrep something like this:

gutengrep.py "^\W*([a-zA-ZåäöÅÄÖàéÉÈ횊]+['[a-zA-Z]+]?[- :;,.¿?\!]+){6}\W*$" --correct --cache > /tmp/1.txt

# Remove blanks and duplicates:
sort /tmp/1.txt | uniq > six-word-sentences.txt  # 

Setup

Before you can use this script you will need to get API credentials from Twitter.

Go to https://developer.twitter.com/en/apps and create a new app. Once approved you will be able to access the credentials below.

consumer_key: TODO_ENTER_YOURS
consumer_secret: TODO_ENTER_YOURS
access_token: TODO_ENTER_YOURS
access_token_secret: TODO_ENTER_YOURS

Copy randomsentencebot_example.yaml to randomsentencebot.yaml, then open randomsentencebot.yaml and replace each TODO_ENTER_YOURS with the value from your Twitter app.