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>