РЕДАКТИРОВАТЬ: Вы можете использовать регулярное выражение, чтобы проверить, что ваш хэштегом является один из последних наборов хэштегов:
import tweepy
import re
consumer_key = 'consumer key'
consumer_secret = 'consumer secret'
access_token = 'access token'
access_token_secret = 'access token secret'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)
# Regular expression to check if tweet ends with our hashtag and maybe more hashtags
rgx = re.compile(r"#not(\s+#\w+)*$", re.IGNORECASE)
for tweet in tweepy.Cursor(api.search,q="#not",count=5,
lang="en",
since="2017-04-03").items():
# Keep only tweets with the hashtag at the end
if rgx.search(tweet.text):
print (tweet.created_at, tweet.text)
Вы можете просто отфильтровать твиты, чтобы оставить только те, которые соответствуют вашим требованиям:
import tweepy
consumer_key = 'consumer key'
consumer_secret = 'consumer secret'
access_token = 'access token'
access_token_secret = 'access token secret'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)
for tweet in tweepy.Cursor(api.search,q="#not",count=5,
lang="en",
since="2017-04-03").items():
# Keep only tweets with the hashtag at the end
if tweet.text.lower().endswith('#not'):
print (tweet.created_at, tweet.text)