Last active
September 18, 2015 08:05
-
-
Save takanakahiko/27e7068703e24d719771 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -*- | |
import json | |
import urllib2 | |
import oauth2 as oauth | |
def streaming(): | |
consumer_key = '' | |
consumer_secret = '' | |
token_key = '' | |
token_secret = '' | |
consumer = oauth.Consumer(key = consumer_key, secret = consumer_secret) | |
token = oauth.Token(key = token_key, secret = token_secret) | |
url = 'https://stream.twitter.com/1.1/statuses/filter.json' | |
params = {'track':'#nowplaying'} | |
request = oauth.Request.from_consumer_and_token(consumer, token, http_url = url, parameters=params) | |
request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token) | |
res = urllib2.urlopen(request.to_url()) | |
for r in res: | |
data = json.loads(r) | |
try: | |
if data['user']['lang'] == 'ja': | |
print data['user']['screen_name'] | |
print data['text'] | |
except: | |
pass | |
if __name__ == '__main__': | |
streaming() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment