Created
April 27, 2020 07:09
-
-
Save lakshay-arora/6743da753c7320cada53be60076c6114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_related_tweets(text_query): | |
# list to store tweets | |
tweets_list = [] | |
# no of tweets | |
count = 50 | |
try: | |
# Pulling individual tweets from query | |
for tweet in api.search(q=text_query, count=count): | |
print(tweet.text) | |
# Adding to list that contains all tweets | |
tweets_list.append({'created_at': tweet.created_at, | |
'tweet_id': tweet.id, | |
'tweet_text': tweet.text}) | |
return pd.DataFrame.from_dict(tweets_list) | |
except BaseException as e: | |
print('failed on_status,', str(e)) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment