mirror of
https://github.com/heyarne/bookmarks-to-kml.git
synced 2026-05-06 18:43:40 +02:00
Match latitude and longitude in description for point which don't have an address
This commit is contained in:
parent
d167158a6e
commit
03f715c88e
1 changed files with 36 additions and 29 deletions
|
|
@ -16,7 +16,8 @@ import sys
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
|
||||||
coords_in_content = re.compile('\/@(-?\d+\.\d+),(-?\d+\.\d+),')
|
coords_in_content = re.compile(r'\/@(-?\d+\.\d+),(-?\d+\.\d+),')
|
||||||
|
coords_in_description = re.compile(r'^(-?\d+\.\d+),(-?\d+\.\d+)$')
|
||||||
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36'
|
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36'
|
||||||
|
|
||||||
filename = r'GoogleBookmarks.html'
|
filename = r'GoogleBookmarks.html'
|
||||||
|
|
@ -42,9 +43,18 @@ for label in doc.body.iterfind('dl/dt/h3'):
|
||||||
for element, _, url, _ in label.getparent().getnext().iterlinks():
|
for element, _, url, _ in label.getparent().getnext().iterlinks():
|
||||||
if 'maps.google' in url:
|
if 'maps.google' in url:
|
||||||
description = element.text or ''
|
description = element.text or ''
|
||||||
|
latitude = longitude = None
|
||||||
|
try:
|
||||||
|
# check if the link itself contains the coordinate
|
||||||
|
latitude, longitude = coords_in_description.search(
|
||||||
|
description).groups()
|
||||||
|
print("Found point {0},{1} in description".format(
|
||||||
|
latitude, longitude))
|
||||||
|
except (AttributeError, IndexError):
|
||||||
safe_query = ['{0}={1}'.format(k, quote_plus(v))
|
safe_query = ['{0}={1}'.format(k, quote_plus(v))
|
||||||
for (k, v) in parse_qsl(urlparse(url).query)]
|
for (k, v) in parse_qsl(urlparse(url).query)]
|
||||||
url = '{0}/?{1}'.format(url.split('/?')[0], '&'.join(safe_query))
|
url = '{0}/?{1}'.format(url.split('/?')
|
||||||
|
[0], '&'.join(safe_query))
|
||||||
|
|
||||||
print('GET {0} {1}'.format(url, description.encode('UTF8')))
|
print('GET {0} {1}'.format(url, description.encode('UTF8')))
|
||||||
browser = Browser()
|
browser = Browser()
|
||||||
|
|
@ -63,16 +73,13 @@ for label in doc.body.iterfind('dl/dt/h3'):
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
coords = coords_in_content.search(content).groups()
|
latitude, longitude = coords_in_content.search(
|
||||||
latitude = coords[0]
|
content).groups()
|
||||||
longitude = coords[1]
|
|
||||||
|
|
||||||
except (AttributeError, IndexError):
|
except (AttributeError, IndexError):
|
||||||
print('[Coordinates not found: ' + str(coords) +
|
print('[Coordinates not found: ({0},{1}).'
|
||||||
'. Try to update "user_agent"]')
|
'Try to update "user_agent"]'.format(latitude, longitude))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(latitude, longitude)
|
|
||||||
try:
|
try:
|
||||||
kml.newpoint(name=description,
|
kml.newpoint(name=description,
|
||||||
coords=[(float(longitude), float(latitude))])
|
coords=[(float(longitude), float(latitude))])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue