Skip to content

Instantly share code, notes, and snippets.

@momota10s
Created January 11, 2015 03:17
Show Gist options
  • Save momota10s/48479846d4dc5ec6a9f1 to your computer and use it in GitHub Desktop.
Save momota10s/48479846d4dc5ec6a9f1 to your computer and use it in GitHub Desktop.
twitter Streaming APIを用いてsampleを取得する為のスクリプトです.ライブラリにtweepyを使っています.基本的にはexampleのデータですが,きれいなjsonが取得出来ない為少し改良しました.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
#key
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
class StdOutListener(StreamListener):
def on_data(self, data):
if data.startswith('{"created_at"'):
print data
print ','
return True
def on_error(self, status):
print status
# del status
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.sample()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment