Skip to content

Instantly share code, notes, and snippets.

@yasushisakai
Last active September 20, 2021 21:51
Show Gist options
  • Save yasushisakai/27829cecbdb59556603f380405fc2f32 to your computer and use it in GitHub Desktop.
Save yasushisakai/27829cecbdb59556603f380405fc2f32 to your computer and use it in GitHub Desktop.
Hack for getting GPS from iOS Pythonista app, you will need the data folder and ‘geolocation.pyui’
import location
import console
import ui
import time
from datetime import datetime
running = True
interval = 5 #sec
def button_tapped(sender):
global running
'@type sender: ui.Button'
running = not running
if running:
sender.title = "recording"
else:
sender.title = "stopped"
print('running switched to: {}'.format(running))
ui.load_view('geolocation').present('sheet')
now = datetime.now()
now_string = "{}{}{}{}{}".format(now.year, now.month, now.day, now.hour,
now.minute, now.second)
with open('data/geolocation{}.csv'.format(now_string), 'w+') as f:
pass
console.set_idle_timer_disabled(True)
location.start_updates()
while True:
if running:
with open('data/geolocation{}.csv'.format(now_string), 'a') as f:
loc = location.get_location()
loc_line = '{},{},{}\n'.format(loc["timestamp"], loc["latitude"],
loc["longitude"])
f.write(loc_line)
print("loc: {}".format(loc_line))
time.sleep(interval)
location.stop_updates()
console.set_idle_timer_disabled(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment