heidilabs/markov-bot

This package is abandoned and no longer maintained. No replacement package was suggested.

A twitter bot using markov-php

0.1 2015-03-11 17:56 UTC

This package is auto-updated.

Last update: 2019-12-14 08:36:33 UTC


README

An open source Twitter bot that uses markov chains to generate tweets. This is basically a simple CLI application written in PHP, using the Symfony console. You can run the commands manually or schedule your bot to tweet periodically by adding the tweet command to crontab.

Requirements

  • php5-cli (cli only, no web server needed) and php5-curl
  • Composer
  • Twitter APP, and proper credentials for the user account in which the tweets will be posted. The easiest thing to do is to create the app using the same account where the tweets will be posted, so you can get the user tokens right away in the app settings page. For detailed instructions, check this tutorial.

Quick Installation Instructions

  1. Run composer create-project heidilabs/markov-bot myDirectory to clone the app repository and install the dependencies
  2. Create your config file by copying config/config-sample.yml to config/config.yml. Edit the file to set your options, including Twitter credentials.
  3. It's ready to use. Run php console.php to see the available commands. To test your current configuration without tweeting it, run php console.php markov:test .

Commands

twitter:test

Test the current Twitter settings and outputs which user is connected and would have the updates posted to, according to the provided keys.

    $ php console.php twitter:test

markov:test

Test the current bot settings and outputs an example of tweet that would be posted using this settings.

    $ php console.php markov:test

markov:tweet

Posts an update to Twitter using the current settings. The tweet is also outputted.

    $ php console.php markov:tweet

cache:update

Updates the cached samples for Twitter and RSS feeds.

    $ php console.php cache:update

Configuring the sources

Currently there are 3 adapters: File, Twitter and RSS. The contents are cached in the first run, and you can run a command to update this cache if you want. It might be interesting to add it to crontab to update once a day, for instance.

Methods

  • wordchain: this will generate a word chain based on the samples you provide. A wordchain basically groups the text into parts of 2 words and try to find, randomly, a complement for each link of the chain. This method works better when you have more content as sample.
  • mixedsource: this method is funny because it mixes two different sources, trying to use a common point of intersection between two sentences.

Sources

Sources can come from a text file, a twitter account, or a RSS feed. The contents are cached locally in a simple txt file. You can update the samples anytime by running php console.php cache:update. The sources are defined using a prefix, followed by the path (in case of local file), url without protocol prefix(in case of RSS) or username (in case of Twitter sources).

  • file://path/to/file.txt
  • twitter://erikaheidi
  • rss://feeds.gawker.com/gizmodo/full

Note: RSS with full content instead of only titles and descriptions work better.

Examples

Using wordchain based on text files

    markov.settings:
        method: wordchain
        sources:
            - file://data/nietzsche.txt
            - file://data/linux.txt

as a charm, that one should be heartily ashamed. To lose the intuition as to the EXTENT to which a process belongs

Using mixedsource based on text files

    markov.settings:
        method: mixedsource
        sources:
            - file://data/nietzsche.txt
            - file://data/mj.txt

riddles which the conflicting nature at the basis of the kid is not my son She says I am the

Using mixedsource based on 2 different twitter users

    markov.settings:
        method: mixedsource
        sources:
            - twitter://erikaheidi
            - twitter://digitalocean

Oh yes. Packing has started! @digitalocean @phpbenelux what a day... setup: Dive into service discovery and learn how it works

Using mixedsource with twitter and text file

    markov.settings:
        method: mixedsource
        sources:
            - twitter://erikaheidi
            - file://data/mj.txt

marvelous. well done @ChasingUX , well done. So excited to always think twice (do think twice.) She told my baby

Using mixedsource with twitter and rss feed

    markov.settings:
        method: mixedsource
        sources:
            - twitter://erikaheidi
            - rss://feeds.gawker.com/gizmodo/full

magician show at #phpbnl15 closing. By the way: I have missed, and it's all on BitStream.... The changing color of

Managing multiple bots

You can run multiple bots within the same installation, for that you just need to create other config files and place them inside your "config" folder. Then, when calling the markov commands, you should provide the --config option, passing the name of the file as parameter.

Example:

    $ php console.php twitter:test --config=other.yml
    $ php console.php twitter:tweet --config=other.yml