您的位置:首页 > 编程语言 > Python开发

Python 获取两个话题的交集

2014-06-23 06:00 260 查看
CODE:

#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Created on 2014-06-28
@author: guaguastd
@name: intersection_between_trends.py
'''

if __name__ == '__main__':

# import login, see http://blog.csdn.net/guaguastd/article/details/31706155 from login import twitter_login

# get the twitter access api
twitter_api = twitter_login()

# import trend
from trend import trend_place

# computing the intersection of two sets of trends
while 1:
woeid1 = int(raw_input("\nInput one wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): "))
if woeid1 == 0:
break

woeid2 = int(raw_input("\nInput another wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): "))
if woeid2 == 0:
break

trends1 = trend_place(twitter_api, woeid1)
trends2 = trend_place(twitter_api, woeid2)
trends_set1 = set([trend['name'] for trend in trends1[0]['trends']])
trends_set2 = set([trend['name'] for trend in trends2[0]['trends']])
common_trend = trends_set1.intersection(trends_set2)
print common_trend


RESULT:

Input one wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 1

Input another wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 23424977
set([u'#NEDvsCRC', u'Happy 5th of July', u'#CostaRicavsHolanda', u'Tim Howard in Spanish', u'#GrantLandisDMMe'])

Input one wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 0<u>
</u>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: