From 0c69ba5d9e7867f7e75ae4d7fe6e6e1dff770ff5 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 25 Feb 2024 15:11:38 +0000 Subject: [PATCH] Add GPX generation --- .gitignore | 5 +++++ README.md | 3 +++ fetch_data.py | 11 +++++++++-- to_gpx.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 README.md create mode 100644 to_gpx.py diff --git a/.gitignore b/.gitignore index 2dc53ca..2518f65 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,8 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + +# Project specific files +data.json +*.osm +*.gpx diff --git a/README.md b/README.md new file mode 100644 index 0000000..77b1a31 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Megalith OSM + +Retrieve data for English megalith sites and convert to an OsmAnd-compatible format diff --git a/fetch_data.py b/fetch_data.py index 8afe2be..cb85128 100644 --- a/fetch_data.py +++ b/fetch_data.py @@ -29,6 +29,8 @@ def get_megalithic_data(country=1): 'lat': row['lat'], 'lng': row['lng'], 'name': row['Name'], + 'type': row['Type'], + 'url': 'https://megalithic.co.uk/article.php?sid={}'.format(row['SID']), }) return data @@ -52,11 +54,16 @@ def get_stone_circles_data(): data.append({ 'lat': item[0], 'lng': item[1], - 'name': re.match(r'.+(.+)', item[2]).groups()[0], + 'name': re.sub(r'<.+?>', '', re.match(r'(.+)', item[2]).groups()[0]), + 'type': re.sub(r'.+>', '', item[2].replace('
', ' ')), + 'url': 'http://www.stone-circles.org.uk/stone/{}'.format(re.search(r'href=([a-zA-Z.]+)', item[2]).groups()[0]), }) return data if __name__ == '__main__': - all_data = get_megalithic_data() + get_stone_circles_data() + all_data = get_stone_circles_data() # + get_megalithic_data() + + with open('data.json', 'w') as f: + json.dump(all_data, f) diff --git a/to_gpx.py b/to_gpx.py new file mode 100644 index 0000000..aaf430c --- /dev/null +++ b/to_gpx.py @@ -0,0 +1,30 @@ +import json +from html import escape + +with open('data.json') as data_file: + data = json.load(data_file) + +with open('Megaliths.gpx', 'w') as gpx_file: + gpx_file.write(''' + + + Megalith sites + + Jude Southworth + + ''') + + for poi in data: + gpx_file.write( + ''' + + {} + {} + {} + '''.format(poi['lat'], poi['lng'], escape(poi['name']), poi['type'], poi['url']) + ) + gpx_file.write('')