Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Created April 27, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakshay-arora/6743da753c7320cada53be60076c6114 to your computer and use it in GitHub Desktop.
Save lakshay-arora/6743da753c7320cada53be60076c6114 to your computer and use it in GitHub Desktop.
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