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)
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))
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)
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]