示例#1
0
    def __init__(self, toml_file="pyborg.reddit.toml"):
        self.toml_file = toml_file
        self.settings = toml.load(toml_file)

        self.last_look = arrow.get(self.settings["reddit"]["last_look"])
        self.multiplexing = self.settings["pyborg"]["multiplex"]
        self.url = "http://www.reddit.com/comments.json?limit=100"
        self.headers = {"user-agent": "pyborg for reddit/0.0.2 pyborg/1.2.0"}

        if not self.multiplexing:
            self.pyborg = pyborg.pyborg()
        else:
            self.pyborg = None
示例#2
0
    def __init__(self, toml_file="reddit.toml"):
        self.toml_file = toml_file
        self.settings = toml.load(toml_file)

        self.last_look = arrow.get(self.settings['reddit']['last_look'])
        self.multiplexing = self.settings['pyborg']['multiplex']
        if self.multiplexing:
            self.multi_server = self.settings['pyborg']['multiplex_server']

        self.hate_filter_off = self.settings['reddit']['hate_filter_disable']

        # script setup, ideal because no oauth browser rigamarole
        self.auth_app_id = self.settings['reddit']['app_id']
        self.auth_script_secret = self.settings['reddit']['script_secret']

        self.reddit = praw.Reddit(client_id=self.auth_app_id,
                                  client_secret=self.auth_script_secret,
                                  user_agent='pyborg for reddit/0.0.3 pyborg/1.3.0')

        if not self.multiplexing:
            self.pyborg = pyborg.pyborg()
        else:
            self.pyborg = None
示例#3
0
    def __init__(self, toml_file="reddit.toml"):
        self.toml_file = toml_file
        self.settings = toml.load(toml_file)

        self.last_look = arrow.get(self.settings['reddit']['last_look'])
        self.multiplexing = self.settings['pyborg']['multiplex']
        if self.multiplexing:
            self.multi_server = self.settings['pyborg']['multiplex_server']

        self.hate_filter_off = self.settings['reddit']['hate_filter_disable']

        # script setup, ideal because no oauth browser rigamarole
        self.auth_app_id = self.settings['reddit']['app_id']
        self.auth_script_secret = self.settings['reddit']['script_secret']

        self.reddit = praw.Reddit(
            client_id=self.auth_app_id,
            client_secret=self.auth_script_secret,
            user_agent='pyborg for reddit/0.0.4 pyborg/2.0.0')

        if not self.multiplexing:
            self.pyborg = pyborg.pyborg()
        else:
            self.pyborg = None
示例#4
0
import bottle
import baker
from bottle import request
from pyborg.pyborg import pyborg

our_pyborg = pyborg()


@bottle.route("/")
def index():
    return "<h1>Welcome to Pyborg/http</h1>"

# Basic API

@bottle.route("/learn", method="POST")
def learn():
    body = request.POST.get("body")
    our_pyborg.learn(body)
    return "OK"


@bottle.route("/reply", method="POST")
def reply():
    body = request.POST.get("body")
    return our_pyborg.reply(body)


# Advanced API

class DumbyIOMod(object):
    message = None
示例#5
0
                    #map ( ( lambda x: c.action(x, "(From "+source+") "+body) ), self.owners)
                    #map ( ( lambda x: c.action(x, "(To   "+source+") "+message) ), self.owners)

if __name__ == "__main__":

    if "--help" in sys.argv:
        print "Pyborg irc bot. Usage:"
        print " pyborg-irc.py [options]"
        print " -s   server:port"
        print " -c   channel"
        print " -n   nickname"
        print "Defaults stored in pyborg-irc.cfg"
        print
        sys.exit(0)
    # start the pyborg
    my_pyborg = pyborg.pyborg()
    bot = ModIRC(my_pyborg, sys.argv)
    try:
        bot.our_start()
    except KeyboardInterrupt, e:
        pass
    except SystemExit, e:
        pass
    except:
        traceback.print_exc()
        c = raw_input("Ooops! It looks like Pyborg has crashed. Would you like to save its dictionary? (y/n) ")
        if c.lower()[:1] == 'n':
            sys.exit(0)
    bot.disconnect(bot.settings.quitmsg)
    my_pyborg.save_all()
    del my_pyborg
示例#6
0
        print "-v --verbose"
        print "-p --port n      Listen on port n (Defaults to 8489)"
        print
        sys.exit(0)

    port = 8489
    if "-p" in sys.argv or "--port" in sys.argv:
        try:
            x = sys.argv.index("-p")
        except ValueError, e:
            x = sys.argv.index("--port")
        if len(sys.argv) > x + 1:
            try:
                port = int(sys.argv[x + 1])
            except ValueError, e:
                pass
    try:
        server = SocketServer.ThreadingTCPServer(("", port), handler)
    except socket.error, e:
        print "Socket error: ", e.args
    else:
        print "Starting pyborg..."
        my_pyborg = pyborg.pyborg()
        print "Awaiting connections..."
        try:
            server.serve_forever()
        except KeyboardInterrupt, e:
            print "Server shut down"
        my_pyborg.save_all()
        del my_pyborg
示例#7
0
 def __attrs_post_init__(self):
     if not self.multiplexing:
         brain_path = os.path.join(folder, "brains", "current.pyborg.json")
         self.pyborg = pyborg.pyborg(brain=brain_path)
示例#8
0
import bottle
import baker
from bottle import request
from pyborg.pyborg import pyborg

our_pyborg = pyborg()


@bottle.route("/")
def index():
    msg = "<h1>Welcome to Pyborg Stats!</h1>\n"
    try:
        msg += "pyborg words = " + ` our_pyborg.settings.num_words `
    except Exception as e:
        msg += str(e)
    return msg


if __name__ == '__main__':
    bottle.run(host="0.0.0.0", port=8085, reloader=True)
#    our_pyborg.save_all()
示例#9
0
 def setup(self, app) -> None:
     self.pyb = pyborg(self.brain_path)
示例#10
0
if __name__ == "__main__":

	try:
		twistoryfile = open("tweets.pck", "r") 
		twistorydict = pickle.load(twistoryfile)
		twistoryfile.close()
	except IOError:
		twistorydict = {"@me":"alive"}
		twistoryfile = open("tweets.pck", "w") 
		pickle.dump(twistorydict, twistoryfile)
		twistoryfile.close()

	
	
	pybot		= pyborg.pyborg()
	api 		= twitter.Api(consumer_key=CKEY, consumer_secret=CSECRET, access_token_key=AKEY, access_token_secret=ASECRET)
	me		= api.VerifyCredentials()
	replytweets	= {}
	
	#print twistorydict

	
	if doPublic:
		print
		print "---------- doPublic"
		#learn some public stauff
		try:
			tweets = api.GetPublicTimeline()
		except Exception:
			print "-- couldnt get public tweets"