Skip to content

Instantly share code, notes, and snippets.

@heyalexej
Created July 10, 2015 11:21
Show Gist options
  • Save heyalexej/8123478243e6deae2a55 to your computer and use it in GitHub Desktop.
Save heyalexej/8123478243e6deae2a55 to your computer and use it in GitHub Desktop.
Get http and https Twitter share counts for https://twitter.com/peeplaja
#!/usr/bin/env python2
import requests, json
api = 'http://urls.api.twitter.com/1/urls/count.json?url='
protocols = ['http://', 'https://']
def get_all(url):
'''check twitter API for URLs with both protocols'''
counts = []
for protocol in protocols:
r = requests.get(api + protocol + url)
data = r.text
x = json.loads(data)
if 'count' in x:
try:
counts.append(x['count'])
except:
pass
print url
print 'List of counts:' ,counts
print 'Sum of counts:' ,sum(counts)
if __name__ == '__main__':
get_all('nomadlist.com')
get_all('www.rustybrick.com')
get_all('en.wikipedia.org/wiki/Usability')
get_all('en.wikipedia.org/wiki/Miley_Cyrus')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment