Created
July 14, 2022 15:39
-
-
Save erichare/ce46e9b5df1986a4664233fd856eb437 to your computer and use it in GitHub Desktop.
Daisi code for the Twitter Search Daisi
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
import tweepy | |
import pandas as pd | |
# Add Twitter API key and secret | |
consumer_key = "<redacted>" | |
consumer_secret = "<redacted>" | |
# Handling authentication with Twitter | |
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret) | |
# Create a wrapper for the Twitter API | |
api = tweepy.API(auth) | |
def fetch_tweets(query: str, count: int=100): | |
... | |
# Search for tweets using Tweepy | |
search = limit_handled(tweepy.Cursor(api.search_tweets, | |
q=query, | |
tweet_mode='extended', | |
lang='en', | |
result_type="recent").items(count)) | |
# Process the results from the search using Tweepy | |
tweets = [] | |
for result in search: | |
tweets.append({"user": result.author.name, "text": result.full_text}) # Only saving the tweet content. | |
# Convert to a dataframe | |
df = pd.DataFrame(tweets) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment