14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Twitter streaming APIでサクサク日本語だけ拾う

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

ところがbottleとかに組み込むと動かないんだよねぇ。
いや、動くんだけど表示しない。

14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?