저는 Tweepy를 사용하여 스트리밍 API를 통해 지역에 대한 트윗을 수집했으며 트위터에 대한 위도/경도 만 수집 했었지만 더 자세히 추가하고 싶습니다. 아르. 나는 위도/경도 값을 얻기 위해 코드 블록을 사용하고 있습니다 :Tweepy에서 Twitter 사용자 이름을 얻는 방법?
import json, tweepy
from html.parser import HTMLParser
consumer_key = ""
consumer_secret = ""
access_token = ""
access_secret = ""
count = 0
class StdOutListener(tweepy.StreamListener):
def on_data(self, data):
global count
decoded = json.loads(HTMLParser().unescape(data))
if decoded.get('coordinates',None) is not None:
coordinates = decoded.get('coordinates','').get('coordinates','')
name = decoded.get('name','')
with open("C:\\Users\\gchre\\Desktop\\Tweets.txt", "a") as text_file:
print(decoded['coordinates'], file=text_file)
print(decoded['coordinates'])
count += 1
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_secret)
stream = tweepy.Stream(auth, l)
while count < 1000000:
stream.filter(locations=[-88.853859,41.220047,-86.953073,42.758134])
나는 또한 텍스트 특정 사용자 이름 (@Handle를) 파일과 트윗이 생성 된 시간에 인쇄이에 대한 싶습니다
. if decoded.get('coordinates',None) is not None:
루프 안에서이 작업을 수행해야하는지 잘 모르겠습니다.