Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location history changes #12

Open
gerardrbentley opened this issue Jan 26, 2023 · 0 comments
Open

location history changes #12

gerardrbentley opened this issue Jan 26, 2023 · 0 comments

Comments

@gerardrbentley
Copy link

not sure if each download is unique, but I had to change some things to work with the takeout zip I made 2023-01-25

filename changed from "Location History.json" to "Records.json"

"timestampMs" is not present, "timestamp" is roughly iso timestamp

def get_timestamp_ms(raw_timestamp):
    try:
        return datetime.datetime.strptime(raw_timestamp, "%Y-%m-%dT%H:%M:%SZ").timestamp()
    except ValueError:
        return datetime.datetime.strptime(raw_timestamp, "%Y-%m-%dT%H:%M:%S.%fZ").timestamp()

def save_location_history(db, zf):
    location_history = json.load(
        zf.open("Takeout/Location History/Records.json")
    )
    db["location_history"].upsert_all(
        (
            {
                "id": id_for_location_history(row),
                "latitude": row["latitudeE7"] / 1e7,
                "longitude": row["longitudeE7"] / 1e7,
                "accuracy": row["accuracy"],
                "timestampMs": get_timestamp_ms(row["timestamp"]),
                "when": row["timestamp"],
            }
            for row in location_history["locations"]
        ),
        pk="id",
    )


def id_for_location_history(row):
    # We want an ID that is unique but can be sorted by in
    # date order - so we use the isoformat date + the first
    # 6 characters of a hash of the JSON
    first_six = hashlib.sha1(
        json.dumps(row, separators=(",", ":"), sort_keys=True).encode("utf8")
    ).hexdigest()[:6]
    return "{}-{}".format(
        row['timestamp'],
        first_six,
    )

example locations from mine

{
    "latitudeE7": 427220206,
    "longitudeE7": -923423972,
    "accuracy": 10,
    "deviceTag": -1312429967,
    "deviceDesignation": "PRIMARY",
    "timestamp": "2019-01-08T23:31:50.867Z"
  }
{
    "latitudeE7": 427011317,
    "longitudeE7": -923448300,
    "accuracy": 5,
    "deviceTag": -1312429967,
    "deviceDesignation": "PRIMARY",
    "timestamp": "2019-01-08T23:33:53Z"
  }, 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant