Add functions to get own tweets and tweets by other users

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-24 16:25:24 +01:00
parent 9354a33589
commit 09d2d75443

View file

@ -178,11 +178,13 @@ def explicitTweet(bot, update, args, reply = None):
else: else:
out = mobj 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() out.close()
else: 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: except tweepy.error.TweepError as e:
bottools.methods.twoExceptions(e, update.message) 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) 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]): def timeline(bot, update, args = [10]):
try: try:
@ -337,7 +361,6 @@ def timeline(bot, update, args = [10]):
db.commit() db.commit()
try: try:
i = 1
two = bottools.methods.getTwo(update.message) two = bottools.methods.getTwo(update.message)
for status in two.api.home_timeline(count=count): for status in two.api.home_timeline(count=count):
@ -438,6 +461,7 @@ commands = {
"reply": reply, "reply": reply,
"restart": restart, "restart": restart,
"retweet": retweet, "retweet": retweet,
"self": selfTweets,
"start": start, "start": start,
"thread": thread, "thread": thread,
"timeline": timeline, "timeline": timeline,
@ -446,6 +470,7 @@ commands = {
"tweet": explicitTweet, "tweet": explicitTweet,
"unauth": unauth, "unauth": unauth,
"unfollow": unfollow, "unfollow": unfollow,
"user": user,
"verify": verify "verify": verify
} }
@ -457,9 +482,11 @@ pargs = [
quote, quote,
reply, reply,
retweet, retweet,
selfTweets,
thread, thread,
timeline, timeline,
toggleTweet, toggleTweet,
user,
explicitTweet, explicitTweet,
unfollow, unfollow,
verify verify