Skip to content

Instantly share code, notes, and snippets.

@hancush
Created August 27, 2015 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hancush/68fb9d4af85df446b24c to your computer and use it in GitHub Desktop.
Save hancush/68fb9d4af85df446b24c to your computer and use it in GitHub Desktop.
check vitals of a twitter account, including: date created, location and time zone, any geolocated tweets, breakdown of tweet sources (mobile v desktop, etc)
from twython import Twython
from config import *
import collections
import re
import requests
requests.packages.urllib3.disable_warnings()
APP_KEY = ckey
APP_SECRET = csecret
OAUTH_TOKEN = atoken
OAUTH_TOKEN_SECRET = asecret
twitter = Twython(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
handle = raw_input("What user? ")
user_object = twitter.lookup_user(screen_name=handle)
tweets = twitter.get_user_timeline(screen_name=handle,count=100)
def basics():
for user in user_object:
print user['name'], "created the account @" + handle, user['created_at'] + "."
print "They've tweeted", user['statuses_count'], "times since then."
print "Here's the account description:", user['description']
print "@" + handle, "is in", user['location'], "and uses the", user['time_zone'], "time zone."
def geo_test():
for user in user_object:
if user['geo_enabled'] == True:
geo_run()
else:
print "@" + handle, "has disabled location services."
def geo_run():
count = 0
print "@" + handle, "has enabled location services."
for status in tweets:
if status['place'] != None:
print "Tweeted from", status['place']['full_name'], "on", status['created_at'], "\b."
count += 1
else:
pass
if count == 0:
print "@" + handle, "has no recent geotagged tweets."
def src_count():
count = []
for status in tweets:
count.append(status['source'])
top_src = str(collections.Counter(count).most_common())
top_src_raw = re.sub("<.*?>", "", top_src)
print "Here's a breakdown of what services they've used to post their most recent 100 tweets:"
print top_src_raw
basics()
geo_test()
src_count()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment