File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 11
11
from io import BytesIO
12
12
import pandas
13
13
import requests
14
+ from datetime import datetime
15
+ from time import sleep
14
16
15
17
URL = 'https://location.services.mozilla.com/v1/geolocate?key=test'
16
18
@@ -35,7 +37,28 @@ def get_nmcli():
35
37
"""
36
38
output: lat lon [deg] accuracy [m]
37
39
"""
38
- ret = get_nmcli ()
39
- loc = ret [ 'location' ]
40
+ import signal
41
+ signal . signal ( signal . SIGINT , signal . SIG_DFL )
40
42
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 )
You can’t perform that action at this time.
0 commit comments