ryanbranch / Tweepier

Python programs to streamline the creation of Markov-Chain-based Twitter bots

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tweepier

Tweepier is a small set of programs, written in Python 2, with the goal of making it easy to create simple Markov chain twitter bots in a very short time.

Files

split.py

split.py is a standalone python program used to divide a large text file into multiple smaller files. This is done to save time with file input and reading, since Twitter bots often run on a sparse schedule and it's unnecessary to read in all information every single time.

By default, split takes a text file called "corpora.txt" and divides it into text files named "corpus_0", "corpus_1", etc. with lengths between 250 and 500 lines. The names of the files themselves are stored in a file called "corpus_filenames.txt". These naming patterns and file lengths can be adjusted by changing the values of the constants at the beginning of the code, however the default settings should work well for most simple applications.

author.py

author.py contains some classes which are used to generate the content to be tweeted. No setup is necessary, as bird should handle all of this stuff.

bird.py

bird.py deals with the communication with Twitter. It calls on author to generate content, using the files generated by split.py, and then posts a tweet using that content.

There are 4 strings that must be specified at the top of the code before bird can run properly. These are "CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_KEY", and "ACCESS_SECRET". These variables should be filled in with the corresponding information from your Twitter Apps page.

There are also other variables which one can customize such as "CHARACTERS_PER_TWEET" (make it lower than 140 if you want shorter tweets), "TUPLE SIZE" (must be an integer greater than or equal to 2. The larger it is, the more coherent -- but less original -- the generated tweets will be), etc.

Getting Started

If you just want to jump right in, here's the bare minimum:

  • Place a text file named "corpora.txt" in the main directory. Tweets will be generated from this text.
  • Run split.py
  • Edit the "CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_KEY", and "ACCESS_SECRET" strings at the top of bird.py to match those specific to your Twitter app.
  • Run bird.py. Each execution posts one tweet, so you might want to set it up to run on a schedule.

Further Information

Tweepier was written by Ryan Branch in March 2016.

As far as licensing, feel free to use this code for any non-commercial application.

About

Python programs to streamline the creation of Markov-Chain-based Twitter bots


Languages

Language:Python 100.0%