with read part obtener how from examples data collecting python twitter dictionary geolocation maps

read - twitter python



Los marcadores de mapa de python folio no se muestran en el mapa a pesar de los datos (2)

Tengo un código que estoy siguiendo del libro práctico de ciencia de datos de libros en el que utilizaron folium y twitter para trazar la ubicación geográfica de los seguidores de Twitter. El código funciona bien y al final muestra un archivo html que se supone que tiene marcadores de dónde están tus seguidores. Sin embargo, mi mapa no tiene ningún marcador a pesar de tener datos.

Aquí está el código:

status_geo = [] status_geo_screen_names = [] for fp in friends_profiles: if (''status'' in fp and fp[''status''][''geo''] is not None and ''screen_name'' in fp): status_geo.append(fp[''status''][''geo'']) status_geo_screen_names.append(fp[''screen_name'']) print status_geo

output: [{u''type '': u''Point'', u''coordinates '': [37.27647779, -121.98564579]}, {u''type'': u''Point '', u''coordinates'': [33.64158125, -84.43924375]} , {u''type '': u''Point'', u''coordinates '': [33.81747122, -116.52908589]}, {u''type'': u''Point '', u''coordinates'': [34.01340657, -118.17538228]}, { u''type '': u''Point'', u''coordinates '': [38.7974924, -76.1285375]}, {u''type'': u''Point '', u''coordinates'': [43.579385, -116.198543]}, {u '' escriba '': u''Point'', u''coordinates '': [51.69102332, -0.41811924]}, {u''type'': u''Point '', u''coordinates'': [40.494286, -74.44376]}, {u''type '' : u''Point '', u''coordinates'': [53.60089695, -113.49052185]}

print status_geo_screen_names

Salida: [u''TicaCoffee '', u''sekouandrews'', u''Kimtuitive '', u''isalsa4u'', u''ConsWahoo '', u''cre8commongood'', u''BrookeHRob '', u''pedrohernandez'', u''khueggen '', u'' DMCONCREPUMP '', u''PhillipLeslie'' ...]

import folium from itertools import izip #Let Folium determine the scale map = folium.Map(location=[38, -120],zoom_start=3) for sg, sn in izip(status_geo, status_geo_screen_names): map.simple_marker(sg[''coordinates''], popup=str(sn)) map.create_map(path=''us_states.html'')

Deberíamos ver algo como esto: pero mi mapa no tiene ningún marcador, no importa donde mire o haga zoom:


Creo que el problema aquí es que NO deberías ver el html generado directamente en el navegador, ya que depende de libs de JavaScript externas que podrían no ser referencia adecuada en un archivo: /// ruta.

Intente usar un servidor de python simple para servir ese archivo.

Primero cd en el directorio donde está el archivo html generado. $ cd / path / to / generated / html / file

$ python -m SimpleHTTPServer 8000

Ahora vaya a su navegador e ingrese http: // localhost: 8000 / us_states.html (en su caso)

Espero que haya ayudado.


Hace poco escribí un código que toma datos brutos de Twitter y crea un archivo CSV con un nombre de usuario, longitud y latitud, que se abre muy bien en Google Earth. Suponiendo que ya tiene los datos brutos de Twitter, debería poder usar esto.

import sys import csv import json in_file = raw_input("File to read ex: ''C://Python27//twitdata.txt'': ") out_file = raw_input("CSV file/location to write: ") csvfile = file(out_file, "w") csvwriter = csv.writer(csvfile) row = [ "user", "latitude", "longitude" ] csvwriter.writerow(row) tweets_file = open(in_file, ''r'') for line in tweets_file: try: tweet = json.loads(line) user = tweet[''user''][''screen_name''] latitude = tweet["geo"]["coordinates"][0] longitude = tweet["geo"]["coordinates"][1] row = [ user, latitude, longitude ] csvwriter.writerow(row) except: continue print "done " csvfile.close()