Created
November 19, 2019 16:18
-
-
Save lamorbidamacchina/f77dc96c59bd84ae3a1995e539e97f4d 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
hashtags = [] | |
mentions = [] | |
tweet_count = 0 | |
end_date = datetime.utcnow() - timedelta(days=365) | |
for status in tweepy.Cursor(api.user_timeline, id=target).items(): | |
tweet_count += 1 | |
if hasattr(status, "entities"): | |
entities = status.entities | |
if "hashtags" in entities: | |
for ent in entities["hashtags"]: | |
if ent is not None: | |
if "text" in ent: | |
hashtag = ent["text"] | |
if hashtag is not None: | |
hashtags.append(hashtag) | |
if "user_mentions" in entities: | |
for ent in entities["user_mentions"]: | |
if ent is not None: | |
if "screen_name" in ent: | |
name = ent["screen_name"] | |
if name is not None: | |
mentions.append(name) | |
if status.created_at < end_date: | |
break | |
most_mentioned_users = "" | |
for item, count in Counter(mentions).most_common(10): | |
most_mentioned_users += item + "\t" + str(count) + "\n" | |
most_used_hashtags = "" | |
for item, count in Counter(hashtags).most_common(10): | |
most_used_hashtags += item + "\t" + str(count) + "\n" | |
processed_tweets = str(tweet_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment