Skip to content

Instantly share code, notes, and snippets.

@mikka2061
Created December 28, 2020 18:27
Show Gist options
  • Save mikka2061/4f2ffcaba9670724d4804561f4bcd60c to your computer and use it in GitHub Desktop.
Save mikka2061/4f2ffcaba9670724d4804561f4bcd60c to your computer and use it in GitHub Desktop.
#!python3
'''
Just a little hacking location data.
'''
import location
import time
import paramiko
import console
import photos
from random import random
import what3words
def getplace_w3w(lat, lon):
geocoder = what3words.Geocoder("<GEOCODER_API>")
return (geocoder.convert_to_3wa(what3words.Coordinates(lat, lon)))
def get_location():
location.start_updates()
time.sleep(2)
myloc = location.get_location()
location.stop_updates()
return myloc
def main():
loctxt = ""
loc = get_location()
w3w = getplace_w3w(loc["latitude"], loc["longitude"])
img = location.render_map_snapshot(
loc['latitude'],
loc['longitude'],
width=500,
height=500,
img_width=1000,
img_height=1000,
map_type='hybrid')
jpeg_data = img.to_jpeg()
filename = w3w["words"] + ".jpg"
with open(filename, 'wb') as f:
f.write(jpeg_data)
asset = photos.create_image_asset(filename)
asset.location = {
'latitude': loc['latitude'],
'longitude': loc['longitude'],
'altitude': loc['altitude']
}
album = [xx for xx in photos.get_albums() if xx.title == "Aerial Mikka"][0]
album.add_assets([asset])
s = console.hud_alert("You're at "+ w3w["words"] + " and saved with success", 'success', 2.3)
exit()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment