Scarygami / location-history-json-converter

Convert the Location History JSON File from Google Takeout into a useable format
Apache License 2.0
468 stars 117 forks source link

-bash: syntax error near unexpected token `(' #49

Closed BullseyeSmith closed 2 years ago

BullseyeSmith commented 2 years ago

Howdy!

This is my first time trying to use location_history_json_converter. I successfully installed python-pip & ijson on Debian 10.

The following execution: python location_history_json_converter.py Records.json output.csv -f csv -s 2021-12-01 (0h00) -e 2021-12-31 (24h00) or python location_history_json_converter.py Records.json output.csv -f csv -s 2021-12-01 (0h00) -e 2021-12-31 (24h00) -i results in the following error:

-bash: syntax error near unexpected token `('

This execution: python location_history_json_converter.py Records.json output.csv -f csv -s 2021-12-01 -e 2021-12-31 or python location_history_json_converter.py Records.json output.csv -f csv -s 2021-12-01 -e 2021-12-31 -i results in the following error:

  File "location_history_json_converter.py", line 406
    print("\r%s / Locations written: %s" % (time.strftime("%Y-%m-%d %H:%M"), added), end="")
                                                                                        ^
SyntaxError: invalid syntax

I see the ^ is pointing to the equal sign in end=""

I also saw you recently changed line 405 from time = datetime.utcfromtimestamp(int(item["timestampMs"]) / 1000) to time = datetime.utcfromtimestamp(int(_get_timestampms(item)) / 1000)

I point out these observations in hopes that they mean something to whoever responds and can guide you in how to fix the code or correct my execution syntax, whichever one is the problem.

Thanks & God bless!

BullseyeSmith commented 2 years ago

I did a little research on the unexpected token error and decided to try the following: python location_history_json_converter.py Records.json output.csv -f csv -s "2021-12-01 (0h00)" -e "2021-12-31 (24h00)" this resulted in the same error that I get when I omit the time:

  File "location_history_json_converter.py", line 406
    print("\r%s / Locations written: %s" % (time.strftime("%Y-%m-%d %H:%M"), added), end="")
                                                                                        ^
SyntaxError: invalid syntax
motophil commented 2 years ago

With bash on MacOS (current):

location_history_json_converter.py Records.json output.csv -f csv -s "2021-12-01 (0h00)" -e "2021-12-31 (24h00)" usage: location_history_json_converter.py [-h] [-f {kml,json,js,jsonfull,jsfull,csv,csvfull,csvfullest,gpx,gpxtracks}] [-i] [-s STARTDATE] [-e ENDDATE] [--starttime STARTTIME] [--endtime ENDTIME] [-a ACCURACY] [-c] [-v VARIABLE] [--separator SEPARATOR] [-p [lat,lon ...]] input output location_history_json_converter.py: error: argument -s/--startdate: Not a valid date: '2021-12-01 (0h00)'.

This looks fine to me - check location_history_json_converter.py -h on --starttime.

Also,

location_history_json_converter.py Records.json output.csv -f csv -s 2021-12-01 -e 2021-12-31 -i

works fine with my Records.json, but produces empty output, which is odd. Same with -f gpxtracks which usually works for me. I'll look into that.

motophil commented 2 years ago

location_history_json_converter.py Records.json output.csv -f csv -s 2021-12-01 -e 2021-12-31 -i

works fine with my Records.json and produces output on my Ubuntu Linux machine on bash. So I upgraded my python installation on my Mac and now it also works fine there.

I recommend you upgrade your python installation to the most current too.

BullseyeSmith commented 2 years ago

It seems the default 'python' on my Debian 10 build was 2.7, but it also has 3.7 available by simply using 'python3'. It still fails when I include time, but when I removed the '(HhMM)' from -s & -e, it worked! What I did NOT realize was that the output only provides Timestamp, Lat, & Long. I have a copy of the Spherical Law of Cosines that I can use to figure out the milage between each timestamp, but I would still be without the From & To addresses. This is not what I need right now in the way of a Mileage Log to finish my taxes. Still a neat app, and I got to learn a bit more code. Thanks for your help.