From 09d2d7544359540718449a379f6ac187fb2b0695 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 24 Mar 2017 16:25:24 +0100 Subject: [PATCH] Add functions to get own tweets and tweets by other users --- bottools/methods.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/bottools/methods.py b/bottools/methods.py index 2dd4e6a..a7c85a6 100644 --- a/bottools/methods.py +++ b/bottools/methods.py @@ -178,11 +178,13 @@ def explicitTweet(bot, update, args, reply = None): else: out = mobj - two.api.update_with_media(filename, update.message.caption, reply, file=out) + status = two.api.update_with_media(filename, update.message.caption, reply, file=out) out.close() else: - two.tweet(' '.join(args), reply) + status = two.tweet(' '.join(args), reply) + + bottools.methods.tweetMessage(status, update.message.chat_id, bot) except tweepy.error.TweepError as e: bottools.methods.twoExceptions(e, update.message) @@ -325,6 +327,28 @@ def tweetMessage(status, cid, bot): bot.sendMessage(chat_id = cid, text = "Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)), reply_markup=rmu) +def user(bot, update, args): + try: + count = int(args[1]) + except: + count = 5 + + try: + two = bottools.methods.getTwo(update.message) + + for status in two.api.user_timeline(args[0], count = args[1]): + tweetMessage(status, update.message.chat_id, bot) + + except tweepy.error.TweepError as e: + bottools.methods.twoExceptions(e, update.message) + +def selfTweets(bot, update, args): + try: + count = int(args[0]) + except: + count = 5 + + bottools.methods.user(bot, update, [bottools.methods.getTwo(update.message).whoami(), count]) def timeline(bot, update, args = [10]): try: @@ -337,7 +361,6 @@ def timeline(bot, update, args = [10]): db.commit() try: - i = 1 two = bottools.methods.getTwo(update.message) for status in two.api.home_timeline(count=count): @@ -438,6 +461,7 @@ commands = { "reply": reply, "restart": restart, "retweet": retweet, + "self": selfTweets, "start": start, "thread": thread, "timeline": timeline, @@ -446,6 +470,7 @@ commands = { "tweet": explicitTweet, "unauth": unauth, "unfollow": unfollow, + "user": user, "verify": verify } @@ -457,9 +482,11 @@ pargs = [ quote, reply, retweet, + selfTweets, thread, timeline, toggleTweet, + user, explicitTweet, unfollow, verify