示例#1
0
def postmsg(username, txt):
    try:
        result = splittxt(txt, 139)
        twitteruser = TwitterUsers("users")
        key, secret = getcreds(getdatadir())
        token = twittertoken(key, secret, twitteruser, username)
        if not token:
            raise TweepError("Can't get twitter token")
        twitter = twitterapi(key, secret, token)
        for txt in result:
            status = twitter.update_status(txt)
        logging.info("logged %s tweets for %s" % (len(result), username))
    except TweepError, ex: logging.error("twitter - error: %s" % str(ex))
    return len(result)
示例#2
0
def postmsg(username, txt):
    try:
        result = splittxt(txt, 139)
        twitteruser = TwitterUsers("users")
        key, secret = getcreds(getdatadir())
        token = twittertoken(key, secret, twitteruser, username)
        if not token:
            raise TweepError("Can't get twitter token")
        twitter = twitterapi(key, secret, token)
        for txt in result:
            status = twitter.update_status(txt)
        logging.info("logged %s tweets for %s" % (len(result), username))
    except TweepError, ex:
        logging.error("twitter - error: %s" % str(ex))
示例#3
0
def handle_wikipedia(bot, ievent):
    """ <what> .. search wikipedia. """
    if not ievent.rest:
        ievent.missing('<what>')
        return
    res = searchwiki(ievent.rest)
    if not res[0]:
        ievent.reply('no result found')
        return
    result = splittxt(res[0])
    if result:
        prefix = u'%s ===> ' % res[1]
        ievent.reply(prefix, result, dot="<br><br>")
    else:
        ievent.reply("no data found on %s" % event.rest)
示例#4
0
def handle_wikipedia(bot, ievent):
    """ <what> .. search wikipedia. """
    if not ievent.rest:
        ievent.missing('<what>')
        return
    res = searchwiki(ievent.rest)
    if not res[0]:
        ievent.reply('no result found')
        return
    result = splittxt(res[0])
    if result:
        prefix = u'%s ===> ' % res[1]
        ievent.reply(prefix, result, dot="<br><br>")
    else:
        ievent.reply("no data found on %s" % event.rest)
示例#5
0
 def less(self, printto, what, nr=365):
     """ split up in parts of <nr> chars overflowing on word boundaries. """
     if type(what) == types.ListType: txtlist = what
     else:
         what = what.strip()
         txtlist = splittxt(what, nr)
     size = 0
     if not txtlist:   
         logging.debug("can't split txt from %s" % what)
         return ["", ""]
     res = txtlist[0]
     length = len(txtlist)
     if length > 1:
         logging.debug("addding %s lines to %s outcache (less)" % (len(txtlist), printto))
         outcache.set(u"%s-%s" % (self.cfg.name, printto), txtlist[1:])
         res += "<b> - %s more</b>" % (length - 1) 
     return [res, length]
示例#6
0
 def less(self, printto, what, nr=365):
     """ split up in parts of <nr> chars overflowing on word boundaries. """
     if type(what) == types.ListType: txtlist = what
     else:
         what = what.strip()
         txtlist = splittxt(what, nr)
     size = 0
     if not txtlist:
         logging.debug("can't split txt from %s" % what)
         return ["", ""]
     res = txtlist[0]
     length = len(txtlist)
     if length > 1:
         logging.debug("addding %s lines to %s outcache (less)" %
                       (len(txtlist), printto))
         outcache.set(u"%s-%s" % (self.cfg.name, printto), txtlist[1:])
         res += "<b> - %s more</b>" % (length - 1)
     return [res, length]