Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (32 sloc) 997 Bytes
#!/usr/bin/env python
import sys
import time
import urllib
import urllib2
import yajl
SEARCH_URL = 'http://search.twitter.com/search.json'
def main():
if not len(sys.argv) == 2:
print 'Requires a couple of arguments'
return -1
since = time.strftime('%Y-%m-%d', time.localtime())
qs = urllib.urlencode({'q' : sys.argv[1], 'since' : since})
url_fd = urllib2.urlopen('%s?%s' % (SEARCH_URL, qs))
body = url_fd.read()
if not body:
print 'Empty body?'
return -1
data = yajl.loads(body)
if not data.get('results'):
return 0
for r in data.get('results', []):
from_user = r.get('from_user', '').lower()
if not from_user:
continue
if from_user == 'jenkinsci':
continue
retweets = r.get('metadata', {}).get('recent_retweets', 0)
print '%s : %s \n\t%s' % (from_user, retweets, r.get('text'))
return 0
if __name__ == '__main__':
sys.exit(main())