Created
June 7, 2013 13:36
-
-
Save spaghetti-source/5729310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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