streamer.py
#!/user/bin/env python
# -*- coding: utf-8 -*-
import tweepy
import json
import sys
import codecs
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
class StdOutListener(tweepy.StreamListener):
def on_data(self, data):
tweet = json.loads(data)
U_img = (tweet["user"]["profile_image_url"])
Created_at = (tweet["created_at"])
User = (tweet["user"]["screen_name"].encode("utf-8"))
Name = (tweet["user"]["name"].encode("utf-8"))
Text = (tweet["text"].encode("utf-8"))
if tweet["user"]["lang"] == "ja":
print Text, User, Name, Created_at
return True
def on_error(self, status):
print status
l = StdOutListener()
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = tweepy.Stream(auth, l)
stream.filter(track=['#'])
Cependant, cela ne fonctionne pas lorsqu'il est installé en bouteille. Non, cela fonctionne, mais cela ne s'affiche pas.
Recommended Posts