Tôi đang cố gắng sử dụng tweepy để tải xuống tweet bằng cách sử dụng vị trí tweet chứ không phải theo vị trí của người dùng. Hiện tại, tôi có thể tải xuống các tweet với vị trí của người dùng nhưng không thể nhận vị trí tweet ngay cả khi geo_enabled
trả về True. Ví dụ: giả sử user_a
là từ New York nhưng anh ấy tweet từ California. Tôi muốn cả vị trí người dùng, New York và vị trí tweet, California.Trích mẩu tweet bằng vị trí tweet và vị trí của người dùng
Code:
import tweepy
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import pandas as pd
import json
import csv
import sys
reload(sys)
sys.setdefaultencoding('utf8')
ckey = 'key'
csecret = 'secret'
atoken = 'token'
asecret = 'secret'
#csvfile = open('StreamSearch.csv','a')
#csvwriter = csv.writer(csvfile, delimiter = ',')
class StdOutListener(StreamListener):
def __init__(self, api=None):
super(StdOutListener, self).__init__()
self.num_tweets = 0
def on_data(self, data):
self.num_tweets += 1
if self.num_tweets < 5: #Remove the limit of no. of tweets to 5
print data
return True
else:
return False
def on_error(self, status):
print status
l = StdOutListener()
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
stream = Stream(auth, l)
stream.filter(locations = [80.10,12.90,80.33,13.24]) #user location
Output
userLocation, userTimezone, Coordinates,GeoEnabled, Language, TweetPlace
London,UK Amsterdam FALSE en null
Aachen,Germany Berlin TRUE de null
Kewaunee Wi TRUE en null
Connecticut, Eastern Time (US & Canada) TRUE en null
TRUE en null
Lahore, City of Gardens London TRUE en null
NAU class of 2018. Arizona FALSE en null
FALSE en null
Pacific Time (US & Canada) FALSE en null
Kết quả đưa ra ở trên được làm sạch phiên bản của dữ liệu lớn. Mặc dù Geolocation
được bật nhưng tôi không thể nhận vị trí tweet và cũng không phải là co-ordinates
.
Câu hỏi rất rộng này, hãy cho chúng tôi biết những gì bạn đã thử. – SIslam
@SIslam Bao gồm mã và đầu ra –
Có thể có liên quan- http://stackoverflow.com/a/16892093/4065350 –