Skip to content

Instantly share code, notes, and snippets.

@Informatic
Last active October 18, 2025 11:55
Show Gist options
  • Save Informatic/f3ccd42e467c848fdda0cb9e868b4e5e to your computer and use it in GitHub Desktop.
Save Informatic/f3ccd42e467c848fdda0cb9e868b4e5e to your computer and use it in GitHub Desktop.
Quick tool to filter Android Timeline.json export by date. Local timeline can be exported using Settings → Location → Location Services → Timeline → Export Timeline data.
import json
import sys
import datetime
import argparse
import logging
logging.basicConfig(level=logging.DEBUG)
p = argparse.ArgumentParser()
p.add_argument("--from", type=datetime.datetime.fromisoformat, dest="from_")
p.add_argument("--to", type=datetime.datetime.fromisoformat)
p.add_argument("--output")
p.add_argument("timeline")
args = p.parse_args()
if args.from_ and args.from_.tzinfo is None:
args.from_ = args.from_.replace(tzinfo=datetime.timezone.utc)
if args.to and args.to.tzinfo is None:
args.to = args.to.replace(tzinfo=datetime.timezone.utc)
with open(sys.argv[1]) as fd:
timeline_data = json.load(fd)
output_data = {}
for k, v in timeline_data.items():
if isinstance(v, list):
logging.info("Processing %r", k)
output_data[k] = []
for i in v:
ts = i.get("timestamp") or i.get("startTime")
if not ts:
first_value = list(i.values())[0]
if isinstance(first_value, dict):
ts = first_value.get("deliveryTime") or first_value.get(
"timestamp"
)
if not ts:
logging.warn("Unparseable record, ignoring: %r", i)
else:
tsd = datetime.datetime.fromisoformat(ts)
if args.from_ and tsd < args.from_:
continue
if args.to and tsd > args.to:
continue
output_data[k].append(i)
logging.info("Output %d/%d records", len(output_data[k]), len(v))
else:
logging.info("Passing through key: %r", k)
logging.debug("%r", v)
output_data[k] = v
if args.output:
with open(args.output, "w+") as fd:
json.dump(output_data, fd)
else:
print(json.dumps(output_data, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment