Add search function
This commit is contained in:
parent
09d2d75443
commit
60c32fcb25
|
@ -279,7 +279,7 @@ def thread(bot, update, args):
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
for tweet in tweets:
|
for tweet in tweets:
|
||||||
tweetMessage(tweet, update.message.chat_id, bot)
|
tweetMessage(tweet, message.chat_id, bot)
|
||||||
|
|
||||||
def like(bot, update, args):
|
def like(bot, update, args):
|
||||||
message = update.message or update.callback_query.message
|
message = update.message or update.callback_query.message
|
||||||
|
@ -327,6 +327,23 @@ 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 search(bot, update, args):
|
||||||
|
try:
|
||||||
|
count = int(args[0])
|
||||||
|
query = ' '.join(args[1:])
|
||||||
|
except:
|
||||||
|
count = 5
|
||||||
|
query = ' '.join(args)
|
||||||
|
|
||||||
|
try:
|
||||||
|
two = bottools.methods.getTwo(update.message)
|
||||||
|
|
||||||
|
for tweet in two.api.search(q=query, rpp=count, result_type="recent")[:count]:
|
||||||
|
tweetMessage(tweet, update.message.chat_id, bot)
|
||||||
|
|
||||||
|
except tweepy.error.TweepError as e:
|
||||||
|
bottools.methods.twoExceptions(e, update.message)
|
||||||
|
|
||||||
def user(bot, update, args):
|
def user(bot, update, args):
|
||||||
try:
|
try:
|
||||||
count = int(args[1])
|
count = int(args[1])
|
||||||
|
@ -461,6 +478,7 @@ commands = {
|
||||||
"reply": reply,
|
"reply": reply,
|
||||||
"restart": restart,
|
"restart": restart,
|
||||||
"retweet": retweet,
|
"retweet": retweet,
|
||||||
|
"search": search,
|
||||||
"self": selfTweets,
|
"self": selfTweets,
|
||||||
"start": start,
|
"start": start,
|
||||||
"thread": thread,
|
"thread": thread,
|
||||||
|
@ -482,6 +500,7 @@ pargs = [
|
||||||
quote,
|
quote,
|
||||||
reply,
|
reply,
|
||||||
retweet,
|
retweet,
|
||||||
|
search,
|
||||||
selfTweets,
|
selfTweets,
|
||||||
thread,
|
thread,
|
||||||
timeline,
|
timeline,
|
||||||
|
|
|
@ -13,8 +13,8 @@ class twObject:
|
||||||
def delete(self, id):
|
def delete(self, id):
|
||||||
self.api.destroy_status(id)
|
self.api.destroy_status(id)
|
||||||
|
|
||||||
def search(self, query, savepoint = 0):
|
def search(self, query, savepoint = 0, count = None):
|
||||||
tweets = list(tweepy.Cursor(self.api.search, q=query, since_id=savepoint, include_entities=True).items())
|
tweets = list(tweepy.Cursor(self.api.search, q=query, since_id=savepoint, count=count, include_entities=True).items())
|
||||||
tweets.reverse()
|
tweets.reverse()
|
||||||
return tweets
|
return tweets
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue