I want to get Chinese tweets from Python using Twitter.

Asked 2 years ago, Updated 2 years ago, 60 views

I would like to get a tweet from python using the program below.
I can speak Japanese and English, but I can't speak Chinese.
Twitter is banned in China.It may also have an effect.
We also use Chinese in Taiwan, so I think we can display it in Chinese.

I would appreciate it if you could let me know if anyone understands.
Thank you for your cooperation.

#-*-coding:utf-8-*-


from tweet.streaming import StreamListener
from tweet import OAuthHandler
from tweet import Stream
import json

# Variables that contain the user credentials to access Twitter API
access_token='xxxxxxxxxxxxxx'
access_token_secret='xxxxxxxxxx'
consumer_key='xxxxxxxxxx'
consumer_secret='xxxxxxxx'


# This is a basic listener that just prints received tweets to stdout.
class StdOutListener (StreamListener):
    defon_data(self,data):
        json_load=json.loads(data)
        texts=json_load ['text']
        coded=texts.encode('utf-8')
        s=str(coded)
        print(s[2:-1])
        return True

    default_error(self, status):
        print(status)

auth=OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream=Stream(auth, StdOutListener())

# This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
stream.filter(track=[u'Tokyo',], languages=['ja'])
 は Thank you ☀
Muffy 1 handsome Bokkun 🎵 But I haven't been able to rank recently 😢
The weather is nice today, so we are looking forward to your visit.
# Owl Cafe #Fukuro Cafe #Mofu #Shinjuku #Tokyo #Tokyo #Owl...https://t.co/e8T0lwq7s
速報Breaking News NTTNTT DoCoMo will dispatch taxis with AI!I think it's due in 2017. - Just remember and write! https://t.co/OKjFxzsBos #Taxi #Artificial Intelligence #NTT #DoCoMo #Tokyo #Olympic�
Narita West 2nd Street, Minami Ward
...it's a good environment.It's a free design by Itochu Corporation's 100% investment subsidiary Itopia Home.First of all, visit the site, including the surrounding environment...For more information, visit the website! 
 https://t.co/yzt9P3mmPY
Ad Expiration Date 16/10/11
 #Real estate #Tokyo #Dogetsu #Shinjo

python twitter

2022-09-30 19:12

1 Answers

I rewritten the last line as follows and it worked.

stream.filter (track=[u'China',], languages=['zh'])

Results

September 29th [Yoshu Jiyudai Shinjo] 亚踪 — 云闻— # 如何 追 南https://t.co/ .... # 9亚 当初泛 [ ? 月 日 p 自由 c 新 29 ] <泛卫道视 < >ode洲 >亚台电····························https://t.co/...

Region only specifies the box enclosed by locations= [longitude, latitude, longitude, latitude].If you click properly on Google Map, you will get latitude and longitude (latitude, longitude).I will be careful because Tweepy is supposed to be specified in the order of (longitude, latitude).When you get 406, try it in a small area with a large population first.Then let's zoom in.

If you specify zh, you won't know the result right away, so I tried ja.

OKINAWA=[127.672482, 26.08887, 128.275025, 26.851451]
stream.filter(languages=['ja'], locations=OKINAWA)

Results

Really!Typhoons never come with Okinawa に


2022-09-30 19:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.