Skip to content

Commit 418d5fe

Browse files
committed
log to disk
1 parent 0af08e9 commit 418d5fe

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

mozloc.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from io import BytesIO
1212
import pandas
1313
import requests
14+
from datetime import datetime
15+
from time import sleep
1416

1517
URL='https://location.services.mozilla.com/v1/geolocate?key=test'
1618

@@ -35,7 +37,28 @@ def get_nmcli():
3537
"""
3638
output: lat lon [deg] accuracy [m]
3739
"""
38-
ret = get_nmcli()
39-
loc = ret['location']
40+
import signal
41+
signal.signal(signal.SIGINT, signal.SIG_DFL)
4042

41-
print(loc['lat'], loc['lng'], ret['accuracy'])
43+
from argparse import ArgumentParser
44+
p = ArgumentParser()
45+
p.add_argument('logfile',help='logfile to append location to',nargs='?')
46+
p = p.parse_args()
47+
48+
T = 60 # fastest allowed polling cadence is 1 minute
49+
50+
logfile = p.logfile
51+
52+
print('updating every {} seconds'.format(T))
53+
while True:
54+
ret = get_nmcli()
55+
loc = ret['location']
56+
stat = '{} {} {} {}'.format(datetime.now().strftime('%xT%X'),
57+
loc['lat'], loc['lng'], ret['accuracy'])
58+
print(stat)
59+
60+
if logfile:
61+
with open(logfile,'a') as f:
62+
f.write(stat+'\n')
63+
64+
sleep(T)

0 commit comments

Comments
 (0)