Skip to main content

Create markov chain ("_ebooks") accounts on Twitter

Project description

Create markov chain (”_ebooks”) accounts on Twitter

The audience for this library is those with at least basic Python experience. Before you set this up, you’ll need:

  • A twitter account

  • A twitter application (register at dev.twitter.com) with authentication keys for the account (read more)

  • A corpus for the bot to learn, which can be a text file or a Twitter archive. Several thousand lines are needed to get decent results

Install

Download or clone the package and run python setup.py install. Feel free to use a virtualenv, if you’re into that.

Brain Train

Train the brain with the twittermarkov_learn command.

The twittermarkov_learn comes with options to ignore replies or retweets, and to filter out mentions, urls, media, and/or hashtags.

When reading an archive, these arguments use the tweet’s metadata to precisely strip the offending content. This may not work well for tweets posted before 2011 or so. For text files or older tweets, a regular expression search is used.

# Usage is twittermarkov_learn ARCHIVE BRAIN
$ twittermarkov_learn twitter/archive/path archive.brain

# teach the brain from a text file
$ twittermarkov_learn --txt file.txt txt.brain

$ twittermarkov_learn --no-replies twitter/archive/path archive-no-replies.brain
# Text like this will be ignored:
# @sample I ate a sandwich

# Text like this will be read in:
# I ate a sandwich with @sample

If you’re using a Twitter archive, the ARCHIVE argument should be the top-level folder of the archive (usually a long name like 16853453_3f21d17c73166ef3c77d7994c880dd93a8159c88). If you have a text file, the argument should be a file name

Config

See the bots.yaml file for a full list of settings. Plug your settings in and save the file as bots.yaml to your home directory or ~/bots. You can also use JSON, if that’s your thing.

At a minimum, your config file will need to look like this:

apps:
    example_app_name:
        consumer_key: ...
        consumer_secret: ...

users:
    example_screen_name:

        key: ...
        secret: ...

        app: example_app_name

        # If you want your bot to continue to learn, include this
        parent: your_screen_name

Read up on dev.twitter.com on obtaining authentication tokens.

First Tweet

Tweeting is easy. By default, the twittermarkov application will learn recent tweets from your parent and send one tweet.

The very first time you tweet, you should use:

$ twittermarkov --tweet --no-learn example_screen_name

After that, use:

$ twittermarkov --tweet example_screen_name

To have your bot reply to mentions, use:

$ twittermarkov --reply example_screen_name

Automating

On a *nix system, set up a cron job like so:

0 10-20 * * * twittermarkov --tweet example_screen_name
15,45 10-20 * * * twittermarkov --reply example_screen_name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twitter_markov-0.2.2.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

twitter_markov-0.2.2.2-py2-none-any.whl (11.7 kB view details)

Uploaded Python 2

File details

Details for the file twitter_markov-0.2.2.2.tar.gz.

File metadata

File hashes

Hashes for twitter_markov-0.2.2.2.tar.gz
Algorithm Hash digest
SHA256 a62dfcef3825749d84599bee3b414cf55600fa02f3d57d9af41d0bba7e7125c4
MD5 f1cee3beacc9e0986c1c84f41ef29fdf
BLAKE2b-256 915ba1f88cc81aa0220eb904aa077b14e3dc9630c14bc9e93683fa5d813fb90c

See more details on using hashes here.

File details

Details for the file twitter_markov-0.2.2.2-py2-none-any.whl.

File metadata

File hashes

Hashes for twitter_markov-0.2.2.2-py2-none-any.whl
Algorithm Hash digest
SHA256 9d33aa7b928a338bf9d4cc24c53c84fa6826d81233ca7b4df5476264cdd928e7
MD5 4650a54147fc7a6bae5856a717eba423
BLAKE2b-256 921398def02dbd5ec406faecdb3fe1fe886e238456bb2700ea03d63ab2180697

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page