tweepy +를 사용하여 특정 영역에서 파이썬으로 CSV 파일에 짹짹 위치를 추출하려고합니다. 나는 파이썬으로 매우 아니다 그러나 나는 함께 다음 sript 작품의 종류 넣어 관리 할 수 있습니다 : 그것은 (30 분 당 10 개 항목처럼) 매우 느리게 좌표를 추출하는 것으로,Python/Tweepy를 사용하여 특정 경계 상자에서 트위터 트윗의 Coordinates 및 TimeStamp를 잡아낼 수 있습니까?
import json
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
#Enter Twitter API Key information
consumer_key = 'cons_key'
consumer_secret = 'cons_secret'
access_token = 'acc_token'
access_secret = 'acc-secret'
file = open("C:\Python27\Output2.csv", "w")
file.write("X,Y\n")
data_list = []
count = 0
class listener(StreamListener):
def on_data(self, data):
global count
#How many tweets you want to find, could change to time based
if count <= 100:
json_data = json.loads(data)
coords = json_data["coordinates"]
if coords is not None:
print coords["coordinates"]
lon = coords["coordinates"][0]
lat = coords["coordinates"][1]
data_list.append(json_data)
file.write(str(lon) + ",")
file.write(str(lat) + "\n")
count += 1
return True
else:
file.close()
return False
def on_error(self, status):
print status
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
twitterStream = Stream(auth, listener())
#What you want to search for here
twitterStream.filter(locations=[11.01,47.85,12.09,48.43])
문제가 있습니다. 이 작업을 더 빠르게 수행 할 수있는 방법이 있습니까?
각 짹짹에 타임 스탬프를 어떻게 추가 할 수 있습니까? 특정 지역에서 가능한 모든 트윗을 검색 할 수있는 방법이 있습니까? (최대치는 지난 주 트윗 모두입니다)?
대단히 감사드립니다.
감사합니다. @ 앤디! 이 코드가 PowerTrack API에서 작동하는지 알고 있습니까? 더 많은 양의 짹짹 (스트리밍하지 않아도 됨)을 무료로 액세스 할 수있는 다른 방법이 있습니까? – Sebastian
이 정확한 코드는 PowerTrack에서 작동하지 않습니다 (끝점이 다르므로 쿼리 구문도 마찬가지 임). 무료 액세스의 측면에서 볼 때 실시간 검색보다는 표준 검색 끝점 만 있으면됩니다. 대신 전화 할 수는 있지만 지리적/위치 데이터가 첨부 된 짹짹의 볼륨 측면에서는 여전히 제한적입니다. –