Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# The output of the script is meant to be piped to an output csv file.
# Usage:
# python > foursquare.csv
import xml.etree.ElementTree as ET
from dateutil import parser
from datetime import *
tree = ET.parse('foursquare.kml') # or whatever the kml file is called
root = tree.getroot()
print ",".join( ['name', 'href', 'datetime', 'lon', 'lat'] ) # csv header
for place in root.iter('Placemark'):
name = place[0].text
href = place[1][0].attrib['href']
datetime = place[2].text
datetime = (parser.parse(datetime) - timedelta(hours = 5)).strftime("%Y-%m-%d %H:%M:%S") # adjusting for timezone and converting to CartoDB-acceptable format
coords = place[5][2].text.split(",")
print '"' + '","'.join( [name, href, datetime, coords[0], coords[1]] ) + '"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment