| 14 | from datetime import datetime |
| 15 | |
| 16 | class GoogleMapsConverter: |
| 17 | def __init__(self, input_file=None, output_format=None, bookmark_list_name=None, api_key=None): |
| 18 | print("Follow these steps to export your saved places from Google Maps and convert them to a GPX or KML File") |
| 19 | print() |
| 20 | print("1. Create an API key for Google Places API following this guide") |
| 21 | print(" https://developers.google.com/maps/documentation/places/web-service/get-api-key") |
| 22 | print("2. Go to https://takeout.google.com/ and sign in with your Google account") |
| 23 | print("3. Select 'Saved' and 'Maps (My Places)' and create an export") |
| 24 | print("4. Download and unzip the export") |
| 25 | print ("5a. Look for CSV files (e.g. for lists) in the folder Takeout/Saved") |
| 26 | print ("5b. Look for GeoJSON files (e.g. for Saved Places) in the folder Takeout/Maps") |
| 27 | print() |
| 28 | |
| 29 | if input_file is None: |
| 30 | self.get_input_file() |
| 31 | else: |
| 32 | self.input_file = input_file |
| 33 | if not path.isfile(self.input_file): |
| 34 | raise FileNotFoundError(f"Couldn't find {self.input_file}") |
| 35 | if not access(self.input_file, R_OK): |
| 36 | raise PermissionError(f"Couldn't read {self.input_file}") |
| 37 | |
| 38 | if output_format is None: |
| 39 | self.get_output_format() |
| 40 | else: |
| 41 | self.output_format = output_format |
| 42 | |
| 43 | if bookmark_list_name is None: |
| 44 | self.get_bookmark_list_name() |
| 45 | else: |
| 46 | self.bookmark_list_name = bookmark_list_name |
| 47 | self.output_file = self.bookmark_list_name + "." + self.output_format |
| 48 | |
| 49 | if api_key is None: |
| 50 | self.get_api_key() |
| 51 | else: |
| 52 | self.api_key = api_key |
| 53 | |
| 54 | self.places = [] |
| 55 | |
| 56 | def get_input_file(self): |
| 57 | while True: |
| 58 | self.input_file = input("Path to the file: ") |
| 59 | if not path.isfile(self.input_file): |
| 60 | print(f"Couldn't find {self.input_file}") |
| 61 | continue |
| 62 | if not access(self.input_file, R_OK): |
| 63 | print(f"Couldn't read {self.input_file}") |
| 64 | continue |
| 65 | break |
| 66 | |
| 67 | def get_output_format(self): |
| 68 | while True: |
| 69 | self.output_format = input("Output format (kml or gpx): ").lower() |
| 70 | if self.output_format not in ['kml', 'gpx']: |
| 71 | print("Please provide a valid output format" + linesep) |
| 72 | continue |
| 73 | else: |
no outgoing calls
no test coverage detected