Skip to content

Instantly share code, notes, and snippets.

@JordanMakesMaps
Created September 25, 2017 12:22
Show Gist options
  • Save JordanMakesMaps/9b095e58f905f492982462ef208710c3 to your computer and use it in GitHub Desktop.
Save JordanMakesMaps/9b095e58f905f492982462ef208710c3 to your computer and use it in GitHub Desktop.
"""
A very simple script that makes you aware the power your stored location
data has on you. From your smartphone, use the location data
tutorial here (https://emerywolf.wordpress.com/)
to view your locations using Google Street View, through
instantstreetview.com.
The script takes the data it needs (lat,lon,time) from JSON file (default=Emery),
converts it (slightly), and stores it in a container. It then
forces open a webbrower using (GeckoDriver) and redirects to instantstreetview.
The search box is identified (Selenium) and every few seconds submits a new query, moving you
forward in spacetime. The user can alter the time at each location (refresh_rate).
Previous locations are saved as green markers on the inset map.
Only locations that are far enough apart (default value = 2000) are stored,
otherwise you spend a lot of time outside a house waiting for someone to wakeup.
This was a fun script to make as it utilizes information we are all aware exists
and is being stored right in our own pockets. It's simple, yet while watching it,
it gives you a feeling of vulnerability, that your privacy is being infringed on.
If a kid on two cups of coffee with nothing to do on a Sunday afternoon can
watch your movements in space in time so easily, imgagine what tech giants and the
military are capable of. #Snowdenforpresident.
TL;Dr
Takes your stored location data and tours you to each location via
Google Street View. Automatically updates.
To run download and install GeckoDriver, place in same folder and/or
provide the location on line 107
Stay inside the webbrowser window to avoid errors/exceptions
(e.g. don't mess with the URL address)
"""
from selenium import webdriver
import webbrowser
import time as father
import urllib
import datetime
import json
import math
#Takes the int values and adds that '.' to make them usable in
#search queries. Code which only works for this hemisphere #'Murica
def addAdot(latitude, longitude):
lat, lon = str(latitude), str(longitude)
lat, lon = lat[:2] + '.' + lat[2:], lon[:3] + '.' + lon[3:]
return lat + ', ' + lon
#Convert the timestampMs to milliseconds, then add Jan 1, 1970
def timeConvert(timestampMs):
date = datetime.datetime.fromtimestamp(int(timestampMs) / 1000)
return date
#thanks euclid, you're the real MVP
def euclid(vector1, vector2):
'''calculate the euclidean distance input'''
dist = [(int(a) - int(b))**2 for a, b in zip(vector1, vector2)]
dist = math.sqrt(sum(dist))
return dist
#Recursive function that automates search queries on website,
#elements are stored outside of function. Exceptions raised sometimes
#when users are trying to view locations while a new query is being made;
#recursion feeds the location back into the loop.
def showLocation(location):
try:
search_input.send_keys(spaceTime[0])
search_input.click()
father.sleep(refresh_rate)
clear_input.click()
return
except Exception:
print('Stop touching stuff!')
showLocation(location)
print("Let the creepin begin...")
#file handling (JSON), reverses to be chronologically correct
parsed_json = json.load(open('Emery.json', 'r'))
Locations = parsed_json['locations']
Locations.reverse()
#creating container for Emery's (cleaned) location variables
print("Loading file...")
Emery = []
prevlat, prevlon = (Locations[0]['latitudeE7']), (Locations[0]['longitudeE7'])
min_distance = 2000
#determining if the distance between two points is far enough to warrent displaying
#if so, converts (lat,lon,time) to proper format, stores in Emery.
for location in Locations:
if euclid([prevlat, prevlon], [location['latitudeE7'], location['longitudeE7']]) > min_distance:
emerys_location = addAdot(location['latitudeE7'], location['longitudeE7'])
time = timeConvert(location['timestampMs'])
Emery.append([emerys_location, time])
prevlat, prevlon = location['latitudeE7'], location['longitudeE7']
print("Locations in space-time created...")
#Setup the webdriver using 'Geckodriver', init url and elements on webpage
#alter refresh_rate to increase the time on each spot.
driver = webdriver.Firefox(executable_path = 'C:\PythonX\Include\geckodriver.exe')
url = 'https://www.instantstreetview.com/'
refresh_rate = 5
#Driver drives, finds elements (searchbox and clear buttons)
print("Opening web browser please wait...")
driver.get(url)
search_input = driver.find_element_by_id('search')
clear_input = driver.find_element_by_id('search-clear')
#runs a loop to the showLocation function, prints location information
for spaceTime in Emery:
print('Space:', spaceTime[0], 'Time:', spaceTime[1])
showLocation(spaceTime)
print("That's all folks!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment