Skip to content

Instantly share code, notes, and snippets.

@spaghetti-source
Created June 7, 2013 13:36
Show Gist options
  • Save spaghetti-source/5729310 to your computer and use it in GitHub Desktop.
Save spaghetti-source/5729310 to your computer and use it in GitHub Desktop.
# coding: utf-8
#
# easy_install tweepy
# easy_install python-dateutil
#
from tweepy import OAuthHandler, Stream
from tweepy.streaming import StreamListener
import tweepy, sys, json
from time import strptime
import datetime, calendar, dateutil.parser
class StreamListener(tweepy.StreamListener):
def on_data(self, data):
if 'text' in data:
tweet = json.loads(data)
if tweet['user']['time_zone'] == 'Tokyo':
enc='sjis'
if 'retweeted_status' in tweet:
retweet = dateutil.parser.parse( tweet['created_at'] )
original = dateutil.parser.parse( tweet['retweeted_status']['created_at'] )
diff = retweet - original
rtcount = tweet['retweeted_status']['retweet_count']
if diff < datetime.timedelta(minutes=10) and rtcount > 10:
if rtcount > diff.seconds / 6.0:
print(u"%d retweets (%f retweets/minute)" % (rtcount, 60.0 * rtcount / diff.seconds))
print(u"Original %s\nRetweeted %s" % (tweet['created_at'], tweet['retweeted_status']['created_at']));
print(tweet['text'].encode(enc, errors='ignore'))
print(" ");
print("--------");
print(" ");
out = open('hotRT.txt', 'a+');
print >>out, (u"%d retweets (%f retweets/minute)" % (rtcount, 60.0 * rtcount / diff.seconds))
print >>out, (u"Original %s\nRetweeted %s" % (tweet['created_at'], tweet['retweeted_status']['created_at']));
print >>out, (tweet['text'].encode(enc, errors='ignore'))
print >>out, (" ");
print >>out, ("--------");
print >>out, (" ");
out.close();
username = "myusername"
password = "mypassword"
auth = tweepy.auth.BasicAuthHandler(username, password)
stream = tweepy.Stream(auth, StreamListener())
stream.sample()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment