2017-09-26 2 views
0

저는 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: 루프 안에서이 작업을 수행해야하는지 잘 모르겠습니다.

답변

1

tweet의 데이터 구조를 이해하려면 Twitter Dev의 설명서를 읽어야한다고 생각합니다.

감사합니다.

user = decoded.get('user','').get('screen_name','') 
date = decoded.get('created_at','') 

그런 다음 인쇄 라인 내에서 내가 추가 한 값 :

print((decoded['coordinates'], user, date), file=text_file) 
관심이있는 사람들을 위해
1

, 내가 그것을 알아 냈의 if decoded.get() 루프 내에서, 나는 다음과 같은 추가
관련 문제