Created
February 25, 2019 16:49
-
-
Save rounakdatta/c245e37042b0ffc80ed2bace9f478fe6 to your computer and use it in GitHub Desktop.
Get the Android/Web/iPhone tweet count for a person
This file contains hidden or 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
from twython import Twython | |
# fill your creds from https://developer.twitter.com | |
apiKey = '' | |
apiSecretKey = '' | |
accessToken = '' | |
accessSecretToken = '' | |
twitter = Twython(apiKey, apiSecretKey, | |
accessToken, accessSecretToken) | |
myDetails = twitter.verify_credentials() | |
# also fill this up | |
userName = '' | |
userDetails = twitter.show_user(screen_name=userName) | |
userTimeline = twitter.get_user_timeline(screen_name=userName) | |
twitterClients = ['Twitter for Android', 'Twitter Web Client', 'Twitter for iPhone'] | |
tweetCollection = [] | |
for tweet in userTimeline: | |
tweetCollection.append(tweet['source']) | |
from bs4 import BeautifulSoup | |
tweetSourceCount = [0, 0, 0] | |
for tweet in tweetCollection: | |
soupOfTweet = BeautifulSoup(tweet) | |
mainSource = soupOfTweet.find('a').text | |
index = twitterClients.index(mainSource) | |
tweetSourceCount[index] += 1 | |
print(tweetSourceCount) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment