Skip to content

Fix KeyError: 'timestampMS #3

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
208 changes: 208 additions & 0 deletions Location_mapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#!/usr/bin/python
import argparse
import json
import sys
import time
from datetime import datetime

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from PIL import Image

from lib.mapperlib import (check_json_file, choose_border_color,
choose_plot_color, create_map, find_border_points,
format_location_history, plot_points,
select_from_dates, valid_date)

print('''
██╗ ██████╗ ██████╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗ ███╗ ███╗ █████╗ ██████╗ ██████╗ ███████╗██████╗
██║ ██╔═══██╗██╔════╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ ████╗ ████║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗
██║ ██║ ██║██║ ███████║ ██║ ██║██║ ██║██╔██╗ ██║█████╗██╔████╔██║███████║██████╔╝██████╔╝█████╗ ██████╔╝
██║ ██║ ██║██║ ██╔══██║ ██║ ██║██║ ██║██║╚██╗██║╚════╝██║╚██╔╝██║██╔══██║██╔═══╝ ██╔═══╝ ██╔══╝ ██╔══██╗
███████╗╚██████╔╝╚██████╗██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║ ██║ ╚═╝ ██║██║ ██║██║ ██║ ███████╗██║ ██║
╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝

''')
print("[*] Google Location Mapper ")
print("[*] Vist `https://takeout.google.com/` get you location")
print("[*] Version 1.1.2")
print("[*] Github Repo 'https://github.com/mrintroverrt/Location-History-Visualizer'")
print("\n")


def calculate_map_boundaries(parsed_json):
'''calculate map boundaries with some space around the most extreme points'''
llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon = find_border_points(
parsed_json)

# determines how many percent of map is shown in addition to extreme points
padding = 0.05

add_to_lat = abs(llcrnrlat - urcrnrlat) * padding
add_to_lon = abs(llcrnrlon - urcrnrlon) * padding

# corrects lower end's scaling difference
lower_lat_scale_correct = 1.9

llcrnrlat -= (add_to_lat * lower_lat_scale_correct)
urcrnrlat += add_to_lat
llcrnrlon -= add_to_lon
urcrnrlon += add_to_lon

return llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon


def plot_points(m, info, relief_bool, colorcode_list=None, title="Location History"):
lons = []
lats = []

print("Almost done: Plotting the points...")

for point in info:
if not "altitude" in point:
continue
x, y = m(point['longitudeE7'] / 10**7, point['latitudeE7'] / 10**7)
lons.append(x)
lats.append(y)

plot_col = choose_plot_color(relief_bool)
plt.plot(lons, lats, color=plot_col, marker='o', markersize=2, zorder=1)

volvlons = [38.239611, 37.473459999999996, 36.268176000000004, 34.796504999999996, 34.392028, 35.068028000000005, 35.316295000000004, 35.164190999999995, 34.349996999999995, 33.478862, 32.046261, 31.320434000000002, 30.590217, 29.627208000000003, 27.169622999999998, 25.347795, 27.208246999999997, 29.099325,
30.285762, 31.894383, 32.656392, 33.972564, 35.679831, 35.805227, 36.467387, 36.562117, 35.757585, 35.804732, 36.682802, 35.801146, 37.104826, 37.943391999999996, 42.317561, 42.434867, 39.772249, 39.646865999999996, 37.239032, 38.568534, 37.920627, 37.49407, 38.173226, 39.727585999999995, 40.514109999999995]
volvlats = [48.276534, 49.497679999999995, 50.008091, 48.506278, 47.440595, 46.604948, 47.001849, 47.801063, 47.076653, 48.372486, 48.836162, 48.697967999999996, 50.242515999999995, 52.559738, 56.251605000000005, 60.597143, 60.690663, 58.346371, 57.07038000000001, 54.346737, 51.645127, 51.40794,
51.412964, 51.466957, 52.347021000000005, 53.059746999999994, 52.769012, 51.4768, 51.432404, 51.472224, 58.488110999999996, 58.348442000000006, 59.141006999999995, 59.601043999999995, 64.420735, 66.967212, 67.277521, 68.775407, 69.7915, 71.556892, 73.96901700000001, 73.24885400000001, 72.808165]

novolvlons = [39.727585999999995, 39.694327, 39.70358, 39.499047999999995, 41.176429999999996, 43.78215, 36.61459, 30.654854999999998,
29.594222, 25.78974, 22.576141, 22.629853, 10.603349, 11.573236, 13.100594000000001, 12.92855, 12.572573, 13.75585, 13.757851]
novolvlats = [73.24885400000001, 73.922437, 75.279597, 75.921746, 80.311706, 87.610449, 101.735883, 104.054938, 106.512196,
113.037995, 114.16185, 113.828529, 103.535278, 104.91841299999999, 103.180746, 102.495168, 101.898062, 100.530392, 100.500702]

fvlats, fvlons = m(volvlats, volvlons)
plt.plot(fvlats, fvlons, color=(0.93, 0.16, 0.22, 0.5),
marker='o', markersize=2, zorder=1, linewidth=2.0)

restlats, restlons = m(novolvlats, novolvlons)
plt.plot(restlats, restlons, color=(0, 0, 0, 0.5),
marker='o', markersize=2, zorder=1, linewidth=2.0)

plt.title(title)

return plt


def choose_border_color(relief_bool):
return (0, 0, 0, 0.5)
# if relief_bool:
# return (0, 0, 0, 0.5)
# return (0.3, 0.3, 0.3, 0.5)


def create_map(llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon, relief_bool, highres, width, map_dpi=300):
'''creates the map'''
print("Building the map. This might take a minute...")

plt.figure(figsize=(width/map_dpi, (width * 0.69)/map_dpi), dpi=map_dpi)
m = Basemap(projection='mill', llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat,
llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, resolution='l')

if highres:
tmpdir = '/Temp'

size = [12000, 6000]
Image.MAX_IMAGE_PIXELS = 233280001
im = Image.open("HYP_HR_SR_W.tif")

im2 = im.resize(size, Image.ANTIALIAS)
im2.save(tmpdir+'/resized.png', "PNG")

m.warpimage(tmpdir+'/resized.png')

if relief_bool:
m.shadedrelief()

country_col = choose_border_color(relief_bool)
m.drawcountries(color=country_col)

m.fillcontinents(color=(0.9, 0.9, 0.9), lake_color='#FFFFFF', zorder=0)
m.drawmapboundary(fill_color='#FFFFFF')

return m


def valid_date(s):
'''raises error if optionally entered dates are not in a format the script can interpret'''
try:
stamp = int(time.mktime(datetime.strptime(
s, "%Y-%m-%d").timetuple()) * 1000)
if len(str(stamp)) != 13:
msg = "ERROR: Cannot convert {} to unix timestamp.".format(s)
raise argparse.ArgumentTypeError(msg)
return stamp

except ValueError:
msg = "Not a valid date: '{0}'.".format(s)
raise argparse.ArgumentTypeError(msg)


def main():
parser = argparse.ArgumentParser(description=("Location History Visualizer: "
"Creates simple maps from google location history."))

parser.add_argument("-i", "--infile", nargs=1, type=str, required=True,
help=("Enter the name or path of the json file downloaded "
"from google takeout, e.g. 'Location_History.json'."))
parser.add_argument("-s", "--startdate", help="Start Date - format YYYY-MM-DD", nargs=1,
type=valid_date, default=False)
parser.add_argument("-e", "--enddate", help="End Date - format YYYY-MM-DD", nargs=1,
type=valid_date, default=False)
parser.add_argument("-t", "--title", help="Enter a title for your map.", type=str,
default=False)
parser.add_argument("-w", "--width", help="Width of your map in pixels. Enter an integer",
type=int, default=6000) # make it work!
parser.add_argument("-relief", help="Set if you want your map to show landscape features",
action='store_true')
parser.add_argument("-highres", help="Set if you want a high resolution shaded relief map",
action='store_true')
parser.add_argument(
"-b", "--banner", action='store_true', help="Show Tool info")

arguments = parser.parse_args()

loc_hist = format_location_history(arguments.infile[0])
oldest_timestamp, newest_timestamp = check_json_file(loc_hist)

if arguments.startdate:
startdate = arguments.startdate[0]
else:
startdate = int(oldest_timestamp)

if arguments.enddate:
enddate = arguments.enddate[0]
else:
enddate = int(newest_timestamp)

if startdate != oldest_timestamp or enddate != newest_timestamp:
loc_hist = select_from_dates(loc_hist, oldest_timestamp, newest_timestamp,
start=startdate, end=enddate)

# llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon = calculate_map_boundaries(loc_hist)

# llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon = 10.603349, 71.1714505, -8.8734426, 114.16185

llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon = 2.5, 74.699855575, - \
15.025207230000001, 120.31361463

m = create_map(llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon,
arguments.relief, arguments.highres, width=arguments.width)
plot_points(m, loc_hist, arguments.relief)

# PLOT MANUAL POINTS HERE?

name = 'your_map{}.png'.format(str(int(time.time())))
plt.savefig(name)
print("Done. Saved the map as {}; bye.".format(name))


if __name__ == "__main__":
main()
65 changes: 48 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,56 @@
# Location History Visualizer
Simple Python CLI tool enabling anyone to visualize the location history that google maps collects - data most likely being collected [whether you want it or not](https://www.independent.co.uk/news/world/americas/google-location-data-privacy-android-sundar-pichai-a8490636.html).

<img src="/outputexamples/basic_example.jpg" alt="output preview_basic" width="350" height="252"> <img src="/outputexamples/relief_example.jpg" alt="output preview_relief" width="350" height="252">

# Installation
```
pip install -r requirements.txt
██╗ ██████╗ ██████╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗ ███╗ ███╗ █████╗ ██████╗ ██████╗ ███████╗██████╗
██║ ██╔═══██╗██╔════╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ ████╗ ████║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗
██║ ██║ ██║██║ ███████║ ██║ ██║██║ ██║██╔██╗ ██║█████╗██╔████╔██║███████║██████╔╝██████╔╝█████╗ ██████╔╝
██║ ██║ ██║██║ ██╔══██║ ██║ ██║██║ ██║██║╚██╗██║╚════╝██║╚██╔╝██║██╔══██║██╔═══╝ ██╔═══╝ ██╔══╝ ██╔══██╗
███████╗╚██████╔╝╚██████╗██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║ ██║ ╚═╝ ██║██║ ██║██║ ██║ ███████╗██║ ██║
╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝


[*] Google Location Mapper
[*] Vist `https://takeout.google.com/` get you location
[*] Version 1.1.2
[*] Github Repo 'https://github.com/mrintroverrt/Location-History-Visualizer'
```

# Basic Usage
- First, [download your own location history here](https://takeout.google.com/) (deselect all, then select "Location History"). Download the archive and unzip the .json file.
- Open your command line, go to the Location History Visualizer's path and type `python location-history-visualizer.py -i name_and_path_of_your.json`. This gives you a simple visualization of your data.
## Description

**Location History Visualizer** is a command-line tool that creates simple maps from Google Location History data. It allows users to generate visualizations of their historical location data, providing insights into travel patterns and visitation frequency.

## Features

- Generate maps from Google Location History data.
- Filter data by start and end dates.
- Customize map title and width.
- Landscape feature and high-resolution map options.

## Usage

1. Clone the repository:

```sh
git clone https://github.com/yourusername/location-history-visualizer.git
cd location-history-visualizer

# Optional Arguments
- Relief: If the `-relief` is set, the output map will show landscape features. Takes a bit longer to generate.
- Start date: `-s YYYY-MM-DD` lets you specify a date from which the visualization should be produced.
- End date: `-e YYYY-MM-DD` sets an end date.
- Width: `-w 6000` adjusts the width of the output image flexibly. Choose a higher integer for more detailed output, a lower for faster output.
- Title: `-t CHOOSE TITLE` gives your map a custom title.
## Installation

# Output
The map can be used to [create detailed relief](/outputexamples/relief_big.jpg) or [schematic maps of your entire data](/outputexamples/basic_big.jpg) and to [visualize itineraries](/outputexamples/reliefdetail3.jpg).
`$ pip install -r requirements.txt`
## Basic Usage

![relief_big](/outputexamples/reliefdetail2.jpg)
Run the script with the following command-line arguments
`python Lctaion-Mapper.py -i Records.json -s 2022-01-01 -e 2022-12-31 -t "My Location History" -w 1200 -relief -highres`
## Arguments
* `-i` or `--infile:` Path to the JSON file downloaded from Google Takeout.
* `-s` or `--startdate:` Start date in YYYY-MM-DD format for data filtering.
* `-e` or `--enddate:` End date in YYYY-MM-DD format for data filtering.
* `-t` or `--title:` Custom title for the Generated map
* `-w` or `--width:` Map width in pixels (default: 6000)
* `-relief:` Show landscape features on the map
* `-highres:` Generate a high-resolution shaded relief map.
## License
This project is licensed under the [MIT](https://choosealicense.com/licenses/mit/) License. See the LICENSE file for details.
## Acknowledgments
* Inspired by the need to visualize personal location history data.
* We appreciate the contributions and feedback from the open-source community
Empty file added __init__.py
Empty file.
Loading