Khai thác dữ liệu Twitter (phần 39)

Định vị các xu hướng: Twitter Trends API (tiếp tục)

Các chủ đề xu hướng New York City

Bây giờ, hãy lấy top 5 các chủ đề xu hướng cho New York City (WOEID 2459115). Code sau thực hiện cùng các nhiệm vụ
như ở trên, nhưng cho WOEID khác:

In [53]: nyc_trends = api.trends_place(id=2459115) # New York City WOEID
In [54]: nyc_list = nyc_trends[0][‘trends’]
In [55]: nyc_list = [t for t in nyc_list if t[‘tweet_volume’]]
In [56]: nyc_list.sort(key=itemgetter(‘tweet_volume’), reverse=True)
In [57]: for trend in nyc_list[:5]:
…: print(trend[‘name’])
…:
#IDOL100M
#TuesdayThoughts
#HappyBirthdayLiam
NAFTA
#USOpen

Chia sẻ