-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Dear Foote,
I try to associate the place info with the tweet, just like the user info. But I get an error.
The sections I made changes and the line I got an error on are as follows. Thanks a lot.
client = tweepy.Client(bearer_token, wait_on_rate_limit=True) hoax_tweets = [] for response in tweepy.Paginator(client.search_all_tweets, query = 'deprem lang:tr', user_fields = ['id', 'name', 'username', 'public_metrics', 'description', 'location', 'verified'], tweet_fields = ['id', 'created_at', 'geo', 'public_metrics', 'text'], place_fields = ['full_name','place_type'], expansions = ['author_id', 'geo.place_id'], start_time = '2023-01-14T00:00:00Z', end_time = '2023-01-15T00:00:00Z', max_results=500): time.sleep(1) hoax_tweets.append(response)
`result = []
user_dict = {}
place_dict = {}
for response in hoax_tweets:
# Take all of the users, and put them into a dictionary of dictionaries with the info we want to keep
for user in response.includes['users']:
user_dict[user.id] = {'username': user.username,
'name': user.name,
'followers': user.public_metrics['followers_count'],
'tweets': user.public_metrics['tweet_count'],
'description': user.description,
'location': user.location,
'verified': user.verified
}
for place in response.includes['places']:
place_dict[place.id] = {'full_name': place.full_name,
'place_type': place.place_type
}
for tweet in response.data:
# For each tweet, find the author's information
author_info = user_dict[tweet.author_id]
# For each tweet, find the places information
place_info = place_dict[tweet.place_id] #**Error Line**
# Put all of the information we want to keep in a single dictionary for each tweet
result.append({'author_id': tweet.author_id,
'username': author_info['username'],
'author_followers': author_info['followers'],
'author_tweets': author_info['tweets'],
'author_description': author_info['description'],
'author_location': author_info['location'],
'text': tweet.text,
'created_at': tweet.created_at,
'retweets': tweet.public_metrics['retweet_count'],
'replies': tweet.public_metrics['reply_count'],
'likes': tweet.public_metrics['like_count'],
'quote_count': tweet.public_metrics['quote_count'],
'tweet_id': tweet.id,
'author_name': author_info['name'],
'verified': author_info['verified'],
'full_name': place_info['full_name'],
'place_type': place_info['place_type']
})`