Skip to content

Commit ca37d96

Browse files
committed
Fixing how to get hashtags
1 parent f6ef0df commit ca37d96

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/tweets.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
consumer_secret = 'YOUR_APP_SECRET'
1818
access_token = 'YOUR_ACCESS_TOKEN'
1919
access_token_secret = 'YOUR_TOKEN_SECRET'
20+
2021
twitter = Twython(consumer_key, consumer_secret, oauth_version=1)
2122

2223
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
@@ -53,6 +54,8 @@ def defineOptions():
5354
users[a['screen_name']] = {}
5455
users[a['screen_name']]['hashtags'] = []
5556

57+
for hashtag in tweet._json['entities']['hashtags']:
58+
users[a['screen_name']]['hashtags'].append(hashtag['text'])
5659

5760

5861
for u in users.keys():
@@ -69,15 +72,22 @@ def defineOptions():
6972
elif g == "undetermined": undefined_c += 1
7073

7174
total_count = len(users)
72-
75+
users['total_count'] = total_count
76+
users['female_count'] = female_c
77+
users['male_count'] = male_c
78+
users['nonbinary_count'] = nonbinary_c
79+
users['undefined_count'] = undefined_c
7380

7481
if len(users) > 0:
7582
female_rate = str((female_c * 100) / total_count)+"%"
7683
male_rate = str((male_c * 100) / total_count)+"%"
7784
nonbinary_rate= str((nonbinary_c * 100) / total_count)+"%"
7885
undefined_rate= str((undefined_c * 100) / total_count)+"%"
7986

80-
87+
users['female_rate'] = female_rate
88+
users['male_rate'] = male_rate
89+
users['nonbinary_rate'] = nonbinary_rate
90+
users['undefined_rate'] = undefined_rate
8191

8292

8393
f = open( '../out/'+args.screen_name+'_tweets.json' , 'w')

0 commit comments

Comments
 (0)