|
# -*- coding: utf-8 -*- |
|
""" |
|
Go to Google Bookmarks: https://www.google.com/bookmarks/ |
|
|
|
On the bottom left, click "Export bookmarks": https://www.google.com/bookmarks/bookmarks.html?hl=en |
|
|
|
After downloading the html file, run this script on it to generate a KML. |
|
|
|
""" |
|
|
|
from lxml.html import document_fromstring |
|
import simplekml |
|
|
|
from urllib2 import urlopen |
|
import re |
|
import time |
|
|
|
filename = r'GoogleBookmarks.html' |
|
|
|
with open(filename) as bookmarks_file: |
|
data = bookmarks_file.read() |
|
|
|
kml = simplekml.Kml() |
|
|
|
# Hacky and doesn't work for all of the stars: |
|
lat_re = re.compile('markers:[^\]]*latlng[^}]*lat:([^,]*)') |
|
lon_re = re.compile('markers:[^\]]*latlng[^}]*lng:([^}]*)') |
|
coords_in_url = re.compile('\?q=(-?\d{,3}\.\d*),\s*(-?\d{,3}\.\d*)') |
|
|
|
doc = document_fromstring(data) |
|
for element, attribute, url, pos in doc.body.iterlinks(): |
|
if 'maps.google' in url: |
|
description = element.text or '' |
|
print description.encode('UTF8') |
|
print u"URL: {0}".format(url) |
|
|
|
if coords_in_url.search(url): |
|
# Coordinates are in URL itself |
|
latitude = coords_in_url.search(url).groups()[0] |
|
longitude = coords_in_url.search(url).groups()[1] |
|
else: |
|
# Load map and find coordinates in source of page |
|
try: |
|
sock = urlopen(url.replace(' ','+').encode('UTF8')) |
|
except Exception, e: |
|
print 'Connection problem:' |
|
print repr(e) |
|
print 'Waiting 2 minutes and trying again' |
|
time.sleep(120) |
|
sock = urlopen(url.replace(' ','+').encode('UTF8')) |
|
content = sock.read() |
|
sock.close() |
|
time.sleep(3) # Don't annoy server |
|
try: |
|
latitude = lat_re.findall(content)[0] |
|
longitude = lon_re.findall(content)[0] |
|
except IndexError: |
|
print '[Coordinates not found]' |
|
print |
|
continue |
|
|
|
print latitude, longitude |
|
try: |
|
kml.newpoint(name=description, |
|
coords=[(float(longitude), float(latitude))]) |
|
except ValueError: |
|
print '[Invalid coordinates]' |
|
print |
|
|
|
kml.save("GoogleBookmarks.kml") |
@heyarne I tried using your script as it's exactly what I need in my situation ( don't have access to old account but downloaded the HTML file), but I got this error 'No module named simplekml '
I tried installing simplekml with pip install simplekmp, but got the following error-
Any help would be appreciated, I'm a super noob here...but could really use all my 1000s of bookmarks in the new account...
Collecting simplekml
Using cached simplekml-1.3.0.zip
Installing collected packages: simplekml
Running setup.py install for simplekml ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/private/var/folders/jk/6y47vn0d2gdcd9v84g51zz8h0000gn/T/pip-build-Vgk14q/simplekml/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /var/folders/jk/6y47vn0d2gdcd9v84g51zz8h0000gn/T/pip-ZB2nDK-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
.......
copying simplekml/coordinates.py -> build/lib/simplekml
copying simplekml/schema.py -> build/lib/simplekml
running install_lib
creating /Library/Python/2.7/site-packages/simplekml
error: could not create '/Library/Python/2.7/site-packages/simplekml': Permission denied