示例#1
0
def handle_twitterfriends(bot, ievent):
    """ no arguments - show friends timeline (your normal twitter feed). """
    if not go:
        ievent.reply(
            "the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples"
        )
        return
    try:
        token = get_token(ievent.user.data.name)
        if not token:
            ievent.reply(
                "you are not logged in yet .. run the twitter-auth command.")
            return
        key, secret = getcreds(getdatadir())
        token = tweepy.oauth.OAuthToken(key, secret).from_string(token)
        twitter = twitterapi(key, secret, token)
        method = getattr(twitter, "friends_timeline")
        result = method()
        res = []
        for item in result:
            try:
                res.append("%s - %s" % (item.author.screen_name, item.text))
            except Exception, ex:
                handle_exception()
        ievent.reply("results: ", res)
示例#2
0
def handle_twitterfriends(bot, ievent):
    """ do a twitter API cmommand. """
    if not go:
        ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples")
        return

    try:
        twitteruser = TwitterUsers("users")
        token = twitteruser.data.get(ievent.user.data.name)
        if not token:
            ievent.reply("you are not logged in yet .. run the twitter-auth command.")
            return 
        key , secret = getcreds(getdatadir())
        token = oauth.OAuthToken(key, secret).from_string(token)
        twitter = twitterapi(key, secret, token)
        method = getattr(twitter, "friends_timeline")

        # do the thing
        result = method()
        res = []
        for item in result:
            try:
                res.append("%s - %s" % (item.author.screen_name, item.text))
                #logging.warn("twitter - %s" % dir(item.author))
                #res.append(unicode(item.__getstate__()))
            except Exception, ex:
                handle_exception()

        ievent.reply("results: ", res) 
示例#3
0
def handle_twittercmnd(bot, ievent):
    """ arguments: <API cmnd> - do a twitter API cmommand. """
    if not go: ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data//config dir. see .jsb/data/examples") ; return
    if not ievent.args: ievent.missing('<API cmnd>') ; return
    target =  strippedtxt(ievent.args[0])
    try:
        from jsb.utils.twitter import get_token
        token = get_token(ievent.user.data.name)
        if not token: ievent.reply("you are not logged in yet .. run the twitter-auth command.") ; return 
        key, secret = getcreds(getdatadir())
        token = tweepy.oauth.OAuthToken(key, secret).from_string(token)
        twitter = twitterapi(key, secret, token)
        cmndlist = dir(twitter)
        cmnds = []
        for cmnd in cmndlist:
            if cmnd.startswith("_") or cmnd == "auth": continue
            else: cmnds.append(cmnd)
        if target not in cmnds: ievent.reply("choose one of: %s" % ", ".join(cmnds)) ; return
        try: method = getattr(twitter, target)
        except AttributeError: ievent.reply("choose one of: %s" % ", ".join(cmnds)) ; return
        result = method()
        res = []
        for item in result:
            try: res.append("%s - %s" % (item.screen_name, item.text))
            except AttributeError:
                try: res.append("%s - %s" % (item.screen_name, item.description))
                except AttributeError:
                    try: res.append(unicode(item.__getstate__()))
                    except AttributeError: res.append(dir(i)) ; res.append(unicode(item))
        ievent.reply("result of %s: " % target, res) 
    except KeyError: ievent.reply('you are not logged in yet. see the twitter-auth command.')
    except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e),))
示例#4
0
def handle_twitterfriends(bot, ievent):
    """ do a twitter API cmommand. """
    if not go:
        ievent.reply(
            "the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples"
        )
        return

    try:
        twitteruser = TwitterUsers("users")
        token = twitteruser.data.get(ievent.user.data.name)
        if not token:
            ievent.reply(
                "you are not logged in yet .. run the twitter-auth command.")
            return
        key, secret = getcreds(getdatadir())
        token = oauth.OAuthToken(key, secret).from_string(token)
        twitter = twitterapi(key, secret, token)
        method = getattr(twitter, "friends_timeline")

        # do the thing
        result = method()
        res = []
        for item in result:
            try:
                res.append("%s - %s" % (item.author.screen_name, item.text))
                #logging.warn("twitter - %s" % dir(item.author))
                #res.append(unicode(item.__getstate__()))
            except Exception, ex:
                handle_exception()

        ievent.reply("results: ", res)
示例#5
0
def handle_twittercmnd(bot, ievent):
    """ arguments: <API cmnd> - do a twitter API cmommand. """
    if not go:
        ievent.reply(
            "the twitter plugin needs the credentials.py file in the .jsb/data//config dir. see .jsb/data/examples"
        )
        return
    if not ievent.args:
        ievent.missing('<API cmnd>')
        return
    target = strippedtxt(ievent.args[0])
    try:
        from jsb.utils.twitter import get_token
        token = get_token(ievent.user.data.name)
        if not token:
            ievent.reply(
                "you are not logged in yet .. run the twitter-auth command.")
            return
        key, secret = getcreds(getdatadir())
        token = tweepy.oauth.OAuthToken(key, secret).from_string(token)
        twitter = twitterapi(key, secret, token)
        cmndlist = dir(twitter)
        cmnds = []
        for cmnd in cmndlist:
            if cmnd.startswith("_") or cmnd == "auth": continue
            else: cmnds.append(cmnd)
        if target not in cmnds:
            ievent.reply("choose one of: %s" % ", ".join(cmnds))
            return
        try:
            method = getattr(twitter, target)
        except AttributeError:
            ievent.reply("choose one of: %s" % ", ".join(cmnds))
            return
        result = method()
        res = []
        for item in result:
            try:
                res.append("%s - %s" % (item.screen_name, item.text))
            except AttributeError:
                try:
                    res.append("%s - %s" %
                               (item.screen_name, item.description))
                except AttributeError:
                    try:
                        res.append(unicode(item.__getstate__()))
                    except AttributeError:
                        res.append(dir(i))
                        res.append(unicode(item))
        ievent.reply("result of %s: " % target, res)
    except KeyError:
        ievent.reply(
            'you are not logged in yet. see the twitter-auth command.')
    except (tweepy.TweepError, urllib2.HTTPError), e:
        ievent.reply('twitter failed: %s' % (str(e), ))
示例#6
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)
示例#7
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))
示例#8
0
def handle_twitterfriends(bot, ievent):
    """ no arguments - show friends timeline (your normal twitter feed). """
    if not go: ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples") ; return
    try:
        token = get_token(ievent.user.data.name)
        if not token: ievent.reply("you are not logged in yet .. run the twitter-auth command.") ; return 
        key , secret = getcreds(getdatadir())
        token = tweepy.oauth.OAuthToken(key, secret).from_string(token)
        twitter = twitterapi(key, secret, token)
        method = getattr(twitter, "friends_timeline")
        result = method()
        res = []
        for item in result:
            try: res.append("%s - %s" % (item.author.screen_name, item.text))
            except Exception, ex: handle_exception()
        ievent.reply("results: ", res) 
    except KeyError: ievent.reply('you are not logged in yet. see the twitter-auth command.')
    except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e),))