About @NopCleanerBot

In our continuing efforts to embrace all “social media”, one of the bots in Naked on Pluto has started a twitter account. Could this be the first character in a FaceBook game to tweet?

The tweeting bot’s actions cause it to wander the world and sporadically report on it’s progress, who is in the same location (bots, players or objects) and snippets of conversations it hears, from players or bots talking to each other. I’m using tweepy, a python twitter library, so I had to do a bit of a cheap hack for the racket->python process communication using the filesystem. The python daemon simply waits for a file to be created by the main bot AI thread and sends the contents of it to the twitter stream. In order to do the authentication with OAuth I needed to set up a Twitter application to get a pair of keys to sign the single user the app will have.

Here is the code for the tweepy daemon:

#!/usr/bin/env python                                                                                   
import tweepy
import os.path
import time

auth = tweepy.OAuthHandler("your consumer key", "your consumer secret")
print(auth.get_authorization_url()) # you need to visit this site, logged in as the twitter user
verifier = raw_input('Verifier:') # then input the verifier code here before continuing
api = tweepy.API(auth) # this api allows us to read or write from the user's account

while True:
    if os.path.isfile("msg"): # look for a file called "msg"
        f = open("msg", "r")
        api.update_status(f.read()) # dump the contents into the twitter stream

One thought on “About @NopCleanerBot”

  1. I did something similar to plot from racket using python:
    #lang racket
    (require racket/system)
    (current-directory (find-system-path ‘home-dir))
    (require srfi/1)
    (define pts 10)
    (define x1 (iota pts))
    (define y1 (map (lambda (x) (* x x)) x1))
    (define y2 (map random (make-list pts (* (- pts 1) (- pts 1)))))
    (display “Starting python…”)
    (define pc (process “python test/plot.py”))
    (display ((fifth pc) ‘status))
    ;;((fifth pc) ‘kill)
    ;(display ((fifth pc) ‘status))
    (write (string-append “[“(string-join (map number->string x1) “,”) “], ” “[“(string-join (map number->string y1) “,”) “], ” “[“(string-join (map number->string x1) “,”) “], ” “[“(string-join (map number->string y2) “,”) “] “) (second pc))
    (write-char (integer->char 13) (second pc))
    (write-char (integer->char 10) (second pc))
    (flush-output (second pc))
    (sleep 10)
    (display ((fifth pc) ‘status))

    python code
    import matplotlib.pyplot as plt
    import string
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    user_input = []
    entry = “”
    #while entry != “done”:
    # user_input.append(entry)
    entry = raw_input(“”)
    #user_input = ‘ ‘.join(user_input)
    #print entry
    file = open(“datafile.txt”, “w”)
    exec “plt.plot(” + string.strip(entry, ‘”‘) + “)”

Leave a Reply to dph3dg Cancel reply

Your email address will not be published. Required fields are marked *