예제 #1
0
 def __init__(self, directory, channel, nickname,
              server, port=6667, sheet=None):
     SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
     self.nickname = nickname
     self.channel = channel
     self.foocount = 0
     self.chump = DailyChump(directory)
     if sheet!=None:
         self.chump.set_stylesheet(sheet)
     self.start()
예제 #2
0
class DailyChumpCmd(Cmd):
    def __init__(self, directory, user):
        self.chump = DailyChump(directory)
        self.user = user

    def start(self):
        self.prompt = "dc> "
        self.cmdloop("Welcome to the Daily Chump")

    def do_quit(self,cmd):
        sys.exit(0)

    def do_database(self,cmd):
        print self.chump.get_database()

    def default(self,line):
        msg = string.rstrip(line)
        output = self.chump.process_input(self.user,msg)
        if output != None:
            print output
예제 #3
0
class DailyChumpCmd(Cmd):
    def __init__(self, directory, user):
        self.chump = DailyChump(directory)
        self.user = user

    def start(self):
        self.prompt = "dc> "
        self.cmdloop("Welcome to the Daily Chump")

    def do_quit(self, cmd):
        sys.exit(0)

    def do_database(self, cmd):
        print self.chump.get_database()

    def default(self, line):
        msg = string.rstrip(line)
        output = self.chump.process_input(self.user, msg)
        if output != None:
            print output
예제 #4
0
def main():
    import sys
    import getopt
    args = sys.argv[1:]
    optlist, args = getopt.getopt(args, 's:p:c:n:d:e:ha:vqiruw:x:', [
        "server=", "port=", "channel=", "nick=", "dir=", "stylesheet=", "help",
        "password="******"version", "quiet", "private", "address", "utf-8", "web",
        "xsl", "pingurl=", "formchatport=", "jabber-id=", "jabber-server=",
        "jabber-password="******"Error: Erroneous web port."
                sys.exit(1)
        elif name in ('-p', '--port'):
            try:
                port = int(value)
            except ValueError:
                print "Error: Erroneous port."
                sys.exit(1)
        elif name in ('-c', '--channel'):
            channel = value
        elif name in ('-n', '--nick'):
            nickname = value
        elif name in ('-d', '--dir'):
            directory = value
        elif name in ('-e', '--stylesheet'):
            sheet = value
        elif name in ('-a', '--password'):
            password = value
        elif name in ('-i', '--private'):
            mode = _M_PRIVMSG
        elif name in ('-q', '--quiet'):
            mode = _M_QUIET
        elif name in ('-r', '--address'):
            addressing = _A_SPECIFIC
        elif name in ('-u', '--utf-8'):
            use_unicode = 1
        elif name in ('-h', '--help'):
            usage(sys.argv[0])
            sys.exit(0)
        elif name in ('-v', '--version'):
            version()
            sys.exit(0)
        elif name in ('--pingurl'):
            pingurls.append(value)
        elif name in ('--formchatport'):
            formchatport = int(value)
        elif name in ('--jabber-server'):
            jabber_server = value
        elif name in ('--jabber-id'):
            jabber_id = value
        elif name in ('--jabber-password'):
            jabber_password = value

    from dailychumptwist import DailyChumpTwistFactory, DailyChumpTwist
    if (directory != '' and channel != '' and nickname != '' and server != ''):
        chump = DailyChump(directory, use_unicode)
        bot = DailyChumpTwistFactory(chump, channel, nickname, sheet, password,
                                     mode, addressing, use_unicode)
        app = service.Application("chump")
        servcoll = service.IServiceCollection(app)
        internet.TCPClient(server, port, bot).setServiceParent(servcoll)
        if len(pingurls) > 0:
            chump.add_listener(URLPinger(servcoll, pingurls))

        if formchatport is not None:
            g = TellChannelSite(chump)
            reactor.listenTCP(formchatport, g)

        if web_port is not None and xsldir is not None:
            try:
                import web
                web.xsldir = xsldir
                web.chumproot = directory
                import quixote.server.twisted_http
                quixote.server.twisted_http.Server("web", web_port)
            except ImportError:
                print "quixote not found, can't start web server"

        service.IService(app).startService()
        if jabber_password is not None and jabber_id is not None and jabber_server is not None:
            TwitterInterface(reactor, chump, jabber_id, jabber_password,
                             jabber_server)

        reactor.run()

    else:
        usage(sys.argv[0])
        sys.exit(1)
예제 #5
0
 def __init__(self, directory, user):
     self.chump = DailyChump(directory)
     self.user = user
예제 #6
0
class DailyChumpBot(SingleServerIRCBot):
    def __init__(self, directory, channel, nickname,
                 server, port=6667, sheet=None):
        SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
        self.nickname = nickname
        self.channel = channel
        self.foocount = 0
        self.chump = DailyChump(directory)
        if sheet!=None:
            self.chump.set_stylesheet(sheet)
        self.start()

    def on_topic(self,c,e):
        if e.arguments()[0] == self.channel:
            topic = e.arguments()[1]
        else:
            topic = e.arguments()[0]
        self.chump.set_topic(topic)

    def on_welcome(self, c, e):
        c.join(self.channel)

    def on_privmsg(self, c, e):
        nick = nm_to_n(e.source())
        output = self.do_command(nick, e.arguments()[0])
        if output != None:
            self.privmsg_multiline(c,nick,output)

    def on_pubmsg(self, c, e):
        msg = e.arguments()[0]
        nick = nm_to_n(e.source())

        a = string.split(msg, ":", 1)

        if len(a) > 1 and irc_lower(a[0]) == irc_lower(self.connection.get_nickname()):
            output = self.do_command(nick, string.strip(a[1]))
        else:
            output = self.chump.process_input(nick, msg)

        if output != None:
            self.notice_multiline(c,output)

    def notice_multiline(self,c,msg):
        for x in string.split(msg,"\n"):
            c.notice(self.channel, x)
            time.sleep(1)

    def privmsg_multiline(self,c,nick,msg):
        for x in string.split(msg,"\n"):
            c.privmsg(nick, x)
            time.sleep(1)

    def do_command(self, nick, cmd):
        c = self.connection

        if cmd == "database":
            data = self.chump.get_database()
            return data 
            #self.notice_multiline(c,data)
        elif cmd == "disconnect":
            self.disconnect()
        elif cmd == "help":
            #self.notice_multiline(c,
            return "Post a URL by saying it on a line on its own\n"+ "To post an item without a URL, say BLURB:This is the title\n"+ "I will reply with a label, for example A\n"+ "You can then append comments by saying A:This is a comment\n"+ "To title a link, use a pipe as the first character of the comment\n"+ "Eg. A:|This is the title\n"+ "To see the last 5 links posted, say "+self.nickname+":view\n" "For more features, say "+self.nickname+":morehelp\n"
                #)
        elif cmd == "morehelp":
            #self.notice_multiline(c,
            return "Put emphasis in a comment by using *asterisks*\n"+ "To create an inline link in a comment, say:\n"+ "A:Look at [this thing here|http://pants.heddley.com]\n"+ "You can also link to inline images in a comment:\n"+ "A:Chump logo +[alt-text|http://pants.heddley.com/chump.png]\n"+ "To see the last n links, say "+self.nickname+":view n (where n is a number)\n"+ "To see the details of a link labelled A, say A: on a line on its own\n"+ "To view a particular comment, say An:, where n is the number of the comment\n" + "To replace, say, the second comment on a link labelled A, say A2:replacement_text\n" + "To delete the second comment on a link labelled A, say A2:\"\"\n" + "To set keywords for a link labelled A, say A:->keyword1 keyword2 etc.\n" + "Send any comments or questions to [email protected]\n"
                #)
        elif cmd == "foo":
            c.action(self.channel,"falls down a well.")
            self.foocount = self.foocount + 1
        elif cmd == "unfoo":
            if self.foocount > 0:
                c.action(self.channel,"clambers out of a well.")
                self.foocount = self.foocount - 1
            else:
                c.action(self.channel,"is not in a well, silly.")
        elif string.find(cmd,"view") == 0:
            viewmatch = re.compile("view\s+(\d+)")
            vm = viewmatch.match(cmd)
            if vm != None:
                count = string.atoi(vm.group(1))
                #self.notice_multiline(c,self.chump.view_recent_items(count))
                return self.chump.view_recent_items(count)
            else:
                #self.notice_multiline(c,self.chump.view_recent_items())
                return self.chump.view_recent_items()
        elif cmd == "die" or cmd == "depart" or cmd == "leave":
            self.die()
        else:
            #c.notice(nick, "Not understood: " + cmd)
            return "Not understood: " + cmd
예제 #7
0
 def __init__(self, directory, user):
     self.chump = DailyChump(directory)
     self.user = user
예제 #8
0
def main():
    import sys
    import getopt
    args = sys.argv[1:]
    optlist, args = getopt.getopt(args,'s:p:c:n:d:e:ha:vqiruw:x:',
                                  ["server=",
                                   "port=",
                                   "channel=",
                                   "nick=",
                                   "dir=",
                                   "stylesheet=",
                                   "help",
                                   "password="******"version",
                                   "quiet",
                                   "private",
                                   "address",
                                   "utf-8",
                                   "web",
                                   "xsl",
                                   "pingurl=",
                                   "formchatport=",
                                   "jabber-id=",
                                   "jabber-server=",
                                   "jabber-password="******"Error: Erroneous web port."
                sys.exit(1)
        elif name in ('-p', '--port'):
            try:
                port = int(value)
            except ValueError:
                print "Error: Erroneous port."
                sys.exit(1)
        elif name in ('-c', '--channel'):
            channel = value
        elif name in ('-n', '--nick'):
            nickname = value
        elif name in ('-d', '--dir'):
            directory = value
        elif name in ('-e', '--stylesheet'):
            sheet = value
        elif name in ('-a', '--password'):
            password = value
        elif name in ('-i', '--private'):
            mode = _M_PRIVMSG
        elif name in ('-q', '--quiet'):
            mode = _M_QUIET
        elif name in ('-r', '--address'):
            addressing = _A_SPECIFIC
        elif name in ('-u', '--utf-8'):
            use_unicode = 1
        elif name in ('-h', '--help'):
            usage(sys.argv[0])
            sys.exit(0)
        elif name in ('-v', '--version'):
            version()
            sys.exit(0)
        elif name in ('--pingurl'):
            pingurls.append (value)
        elif name in ('--formchatport'):
            formchatport = int(value)
        elif name in ('--jabber-server'):
            jabber_server = value
        elif name in ('--jabber-id'):
            jabber_id = value
        elif name in ('--jabber-password'):
            jabber_password = value

    from dailychumptwist import DailyChumpTwistFactory, DailyChumpTwist
    if(directory != '' and channel != '' and
       nickname != '' and server != ''):
        chump = DailyChump(directory, use_unicode)
        bot = DailyChumpTwistFactory(chump, channel, nickname,
                            sheet, password,
                            mode, addressing, use_unicode)
        app = service.Application("chump")
        servcoll = service.IServiceCollection(app)
        internet.TCPClient (server, port, bot).setServiceParent(
                servcoll)
        if len(pingurls)>0:
            chump.add_listener (URLPinger(servcoll, pingurls))

        if formchatport is not None:
            g = TellChannelSite (chump)
            reactor.listenTCP (formchatport, g)

	if web_port is not None and xsldir is not None:
            try:
                import web
                web.xsldir = xsldir
                web.chumproot = directory
                import quixote.server.twisted_http
                quixote.server.twisted_http.Server("web", web_port)
            except ImportError:
                print "quixote not found, can't start web server"

        service.IService(app).startService ()
        if jabber_password is not None and jabber_id is not None and jabber_server is not None:
            TwitterInterface(reactor, chump, jabber_id, jabber_password, jabber_server)

        reactor.run ()

    else:
        usage(sys.argv[0])
        sys.exit(1)
예제 #9
0
import BaseHTTPServer
import re
import urllib
import string
from xml.xslt.Processor import Processor
from dailychump import DailyChump

BaseClass = BaseHTTPServer.BaseHTTPRequestHandler
chump = DailyChump("/tmp")


# code from
# http://www.faqts.com/knowledge_base/view.phtml/aid/4373
def urlParse(url):
    """ return path as list and query string as dictionary
        strip / from path
        ignore empty values in query string
        for example:
            if url is: /xyz?a1=&a2=0%3A1
            then result is: (['xyz'], { 'a2' : '0:1' } )
            if url is: /a/b/c/
            then result is: (['a', 'b', 'c'], None )
            if url is: /?
            then result is: ([], {} )
    """
    print "Parsing: " + url
    #x = string.split(url, '?')
    query_split = re.compile("([^?]*)\?(.*)")
    var_split = re.compile("([^=]*)=(.*)")
    match = query_split.match(url)
    if match != None: