import twitter import json import pygmaps import webbrowser import pprint as pp CONSUMER_KEY = 'qAhZWyyxyi8MQZwxaCKojiC8O' CONSUMER_SECRET = 'vCvQvS8icQpNucs5e42JZ0YqdmZkFg6QeGE3PH1sSUeZYyKzvC' OAUTH_TOKEN = '2892604311-sLujj8H3JB5oHbIVPGZhC2vkZYNbW3CJsh2LICs' OAUTH_TOKEN_SECRET = '9MFpHT1HKFmMyf3XD1UzH8APE0QwpkgbDEqt95GHmWQcw' auth = twitter.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET) twitter_api = twitter.Twitter(auth=auth) #Create a google map with the origin in the center of the laid out world #zoom is 2 so that we can see all countries mymap = pygmaps.maps(0, 0, 3) for i in range(1,6): if i == 1: #Israel name = 'Israel' trends = twitter_api.trends.place(_id=23424852) lat = 31.00 lon = 35.00 if i == 2: #Mexico name = 'Mexico' trends = twitter_api.trends.place(_id=23424900) lat = 19.428 lon = -99.127 if i == 3: #Brazil name = 'Brazil' trends = twitter_api.trends.place(_id=23424768) lat = -15.7797 lon = -47.9297 if i == 4: #France name = 'France' trends = twitter_api.trends.place(_id=23424819) lat = 48.8534 lon = 2.3488 if i == 5: #Russia name = 'Russia' trends = twitter_api.trends.place(_id=23424936) lat = 60.00 lon = 90.00 stop = len(trends[0]['trends']) print stop trendsLabel = [None]*5 for i in range(0,stop): try: trendsLabel[i] = trends[0]['trends'][i]['name'] print i except KeyError, e: print e finally: if i == 5: break pp.pprint(trendsLabel) mymap.addpoint(lat, lon, "#FF0000", str(trendsLabel)) print #draw the google map with all our coordinates on it #and save it in this directory mymap.draw('./mymap.html') #open this file in the browser automatically webbrowser.open_new('mymap.html') #Display the map here in the ipython document from IPython.display import HTML HTML('')