갈루아의 반서재


Yahoo GeoPlanet 를 이용하여 트위터에서 유행하는 주제를 알아보자.

야후 GeoPlanet 의 Where On Earth(WOE) ID 시스템은 지구상의 장소와 고유의 식별자를 매핑시키는 방법을 제공한다.

이 API 를 이용하여 한정된 쿼리를 실행해보자.


[참조링크]

https://dev.twitter.com/rest/reference/get/trends/place

https://developer.yahoo.com/geo/geoplanet/guide/concepts.html


[WOE ID 검색]

아래의 사이트를 통해서 WOE ID를 찾을 수 있다.

http://woeid.rosselliot.co.nz/


서울의 경우 1132599 이다.


District-County


Province-StateCountryWOEID

SeoulSouth Korea1132599





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.shortcuts import render_to_response, render, redirect
import twitter
 
def get_twitter_data(request):
 
    CONSUMER_KEY = '****************'
    CONSUMER_SECRET = '****************'
    OAUTH_TOKEN = '****************'
    OAUTH_TOKEN_SECRET = '****************'
    auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,  CONSUMER_KEY, CONSUMER_SECRET)
    twitter_api = twitter.Twitter(auth=auth)
 
    WORLD_WOE_ID = 1
    US_WOE_ID = 23424977
    
    world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID)
    us_trends = twitter_api.trends.place(_id=US_WOE_ID)
    
    return render(request, 'blog/twitterdata.html', {
            'twitter_api': twitter_api,
            'world_trends': world_trends,
            'us_trends': us_trends,
        })
 
 
 
cs




아래와 같이 딕셔너리 리스트 형태의 응답을 확인할 수 있다.

다음편에서 더 쉽게 읽을 수 있도록 형태를 변환해보자.




※ 본 포스팅은 아래 도서의 소스를 참고하여 학습목적으로 작성되었습니다.

소셜 웹 마이닝
국내도서
저자 : 매튜 러셀(Matthew A. Russell) / 김상정역
출판 : 비제이퍼블릭 2015.02.25
상세보기