DovarFalcone / google-takeout-location-parser

Easily parse location .json files provided by the Google Takeout service
MIT License
20 stars 3 forks source link

KeyError: 'address' #1

Closed sturmi closed 1 year ago

sturmi commented 1 year ago

Hi, thank you for your script. It is exactly what I needed :-) I got exception parsing some YYYY_MONTH.json files: ` File "/home/ts/RTS/googledata/semantic_location_parser.py", line 18, in process_file address = obj['placeVisit']['location']['address'] KeyError: 'address'

So I added thisto semantic_location_parser.py in line 15: try: address = obj['placeVisit']['location']['address'] except KeyError: address = obj['placeVisit']['location']['name']`

regards Thomas

DovarFalcone commented 1 year ago

So you had to swap around the try and exception lines? Wonder why that fixed i it. Can you paste the error you were receiving? I wonder if there's an additional key value that wasn't in my json it wasn't handling. if you'd like to raise a pull request feel free. Glad this helped you out

sturmi commented 1 year ago

So you had to swap around the try and exception lines? Wonder why that fixed i it. Can you paste the error you were receiving? I wonder if there's an additional key value that wasn't in my json it wasn't handling. if you'd like to raise a pull request feel free. Glad this helped you out

Hi, this is the full error message I received: `$ python semantic_location_parser_org.py Traceback (most recent call last): File "/home/ts/RTS/googledata/semantic_location_parser_org.py", line 47, in main() File "/home/ts/RTS/googledata/semantic_location_parser_org.py", line 44, in main process_file(file_path, data_writer) File "/home/ts/RTS/googledata/semantic_location_parser_org.py", line 18, in process_file address = obj['placeVisit']['location']['address'] KeyError: 'address'

The csv file is filled correctly until the error `appears. I have 20 YYYY_MONTH.json files. 17 will be parsed correctly. Only with 3 of them I got the error. So I decided to add the exception handler for "address"