Skip to content

Instantly share code, notes, and snippets.

@rounakdatta
Created February 25, 2019 16:49
Show Gist options
  • Save rounakdatta/c245e37042b0ffc80ed2bace9f478fe6 to your computer and use it in GitHub Desktop.
Save rounakdatta/c245e37042b0ffc80ed2bace9f478fe6 to your computer and use it in GitHub Desktop.
Get the Android/Web/iPhone tweet count for a person
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