diff options
author | kongr45gpen <kongr45gpen@helit.org> | 2013-07-23 23:53:29 +0300 |
---|---|---|
committer | kongr45gpen <kongr45gpen@helit.org> | 2013-07-23 23:53:29 +0300 |
commit | 523e485414d16c836509063a85d189f95ad79fb8 (patch) | |
tree | 03639da5d1cb67b110a03a7f23f0081d25fbff0d | |
parent | 382878b7d2a4b98d346a5e5df30b638f23a92ab6 (diff) | |
download | supybot_github-523e485414d16c836509063a85d189f95ad79fb8.tar.gz supybot_github-523e485414d16c836509063a85d189f95ad79fb8.tar.bz2 supybot_github-523e485414d16c836509063a85d189f95ad79fb8.zip |
Tidy up a bit
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | plugin.py | 115 |
2 files changed, 68 insertions, 51 deletions
@@ -1,4 +1,4 @@ -***supybot-github*** is a plugin for the python-based IRC bot Supybot. +**supybot-github** is a plugin for the python-based IRC bot Supybot. Its purpose is to announce commits and other important notifications from a Github repository on an IRC channel, using Github's post commit hooks. @@ -10,7 +10,7 @@ my bad python coding style. Getting started ============== -**Installation instructions to be put here...** +*Installation instructions to be put here...* Todo ==== @@ -1,4 +1,5 @@ -### +#!/usr/bin/python +# -*- coding: utf-8 -*- import random import json @@ -12,69 +13,85 @@ import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks + class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): - def do_POST(s): - """Respond to a POST request.""" - length = int(s.headers['Content-Length']) - data = json.loads(s.rfile.read(length).decode('utf-8')) - - s.send_response(200) - s.send_header("Content-type", "text/html") - s.end_headers() - s.wfile.write("<html><head><title>Hello</title></head>") - s.wfile.write("<body><p>Thanks, you're great.</p>") - #s.wfile.write("<p>POST: You accessed path: %s</p>" % s.path) - s.wfile.write("</body></html>") - s.wfile.write(vars(s)) - print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) + + def do_POST(s): + """Respond to a POST request.""" + + length = int(s.headers['Content-Length']) + data = json.loads(s.rfile.read(length).decode('utf-8')) + + s.send_response(200) + s.send_header('Content-type', 'text/html') + s.end_headers() + s.wfile.write('<html><head><title>Hello</title></head>') + s.wfile.write("<body><p>Thanks, you're great.</p>") + + s.wfile.write('</body></html>') + s.wfile.write(vars(s)) + print json.dumps(data, sort_keys=True, indent=4, separators=(',' + , ': ')) + class Github(callbacks.Plugin): - """Add the help for "@plugin help Github" here + + """Add the help for \"@plugin help Github\" here This should describe how to use this plugin.""" + threaded = True pass - def ServerStart(main,httpd,irc): - try: - print time.asctime(), "Server Starts - %s:%s" % ('', 8093) - httpd.serve_forever() - except: + def ServerStart(main, httpd, irc): + try: + print time.asctime(), 'Server Starts - %s:%s' % ('', 8093) + httpd.serve_forever() + except: return def __init__(self, irc): - self.__parent = super(Github, self) - self.__parent.__init__(irc) - self.rng = random.Random() # create our rng - self.rng.seed() # automatically seeds with current time - server_class = BaseHTTPServer.HTTPServer - self.httpd = server_class(('', 8093), GithubHandler) - t = threading.Thread(target=self.ServerStart,args=(self.httpd,irc)) - t.daemon = False - t.start() - - + self.__parent = super(Github, self) + self.__parent.__init__(irc) + self.rng = random.Random() # create our rng + self.rng.seed() # automatically seeds with current time + server_class = BaseHTTPServer.HTTPServer + self.httpd = server_class(('', 8093), GithubHandler) + t = threading.Thread(target=self.ServerStart, args=(self.httpd, + irc)) + t.daemon = False + t.start() + def __call__(self, irc, msg): - self.__parent.__call__(irc, msg) - print "I have no idea what is happeninig" - + self.__parent.__call__(irc, msg) + print 'I have no idea what is happeninig' + def die(self): - print "OH NOES IM DYING" - self.httpd.server_close() - self.__parent.die() + print 'OH NOES IM DYING' + self.httpd.server_close() + self.__parent.die() - def toast(self, irc, msg, args, seed, items): - """<seed> <item1> [<item2> ...] + def toast( + self, + irc, + msg, + args, + seed, + items, + ): + """<seed> <item1> [<item2> ...] - Returns the next random number from the random number generator. - """ - if seed < len(items): - irc.error('<number of items> must be less than the number of arguments.') - return - irc.reply(str(seed) + str(self.rng.random()) + utils.str.commaAndify(items)) - toast = wrap(toast,['float', many('anything')]) +........Returns the next random number from the random number generator. +........""" + if seed < len(items): + irc.error('<number of items> must be less than the number of arguments.' + ) + return + irc.reply(str(seed) + str(self.rng.random()) + + utils.str.commaAndify(items)) + + toast = wrap(toast, ['float', many('anything')]) -Class = Github +Class = Github -# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: |