Pick up only crispy Japanese with Twitter streaming API

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=['#'])

However, if you install it in a bottle, it won't work. No, it works, but it doesn't display.

Recommended Posts

Pick up only crispy Japanese with Twitter streaming API
Use Twitter API with Python
Support yourself with Twitter API
Successful update_with_media with twitter API
Specifying the date with the Twitter API
Collecting information from Twitter with Python (Twitter API)
Streaming speech recognition with Google Cloud Speech API
Post from another account with Twitter API
Automatic follow-back using streaming api with Tweepy
Tweet regularly with the Go language Twitter API