Last active
August 29, 2015 14:16
-
-
Save shippy/26cf39b395dac04ff62f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The output of the script is meant to be piped to an output csv file. | |
# Usage: | |
# python foursquare-parse.py > 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