Skip to content

Commit

Permalink
new default: server OFF and just print signal data
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Sep 19, 2024
1 parent 258fab1 commit 24dbec7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
10 changes: 3 additions & 7 deletions src/mozloc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
default=60,
type=float,
)
p.add_argument(
"-url",
help="Mozilla location services URL--don't use this default test key",
default="https://location.services.mozilla.com/v1/geolocate?key=test",
)
p.add_argument("-url", help="Location service URL")
p.add_argument(
"-d", "--dump", help="print raw data to console without logging", action="store_true"
)
Expand All @@ -37,6 +33,6 @@
if args.dump:
pprint(get_signal(scan_signal()))
elif args.infile:
process_file(args.infile, mozilla_url=args.url)
process_file(args.infile, url=args.url)
else:
log_wifi_loc(cadence_sec=args.cadence, mozilla_url=args.url, logfile=args.logfile)
log_wifi_loc(cadence_sec=args.cadence, url=args.url, logfile=args.logfile)
35 changes: 20 additions & 15 deletions src/mozloc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
HEADER = "time lat lon accuracy NumBSSIDs"


def process_file(file: Path, mozilla_url: str):
def process_file(file: Path, url: str | None = None):
"""
process raw data captured from NetSH etc. by user previously to a file
"""

raw = Path(file).expanduser().read_text()
dat = get_signal(raw)
pprint(dat)
loc = get_loc_mozilla(dat, url=mozilla_url)

stat = f'{loc["t"].isoformat(timespec="seconds")} {loc["lat"]} {loc["lng"]} {loc["accuracy"]:.1f} {loc["N"]:02d}'
if url:
loc = get_loc_mozilla(dat, url)

print(stat)
stat = f'{loc["t"].isoformat(timespec="seconds")} {loc["lat"]} {loc["lng"]} {loc["accuracy"]:.1f} {loc["N"]:02d}'

print(stat)


def log_wifi_loc(cadence_sec: float, mozilla_url: str, logfile: Path | None = None):
def log_wifi_loc(cadence_sec: float, url: str | None = None, logfile: Path | None = None):
if logfile:
logfile = Path(logfile).expanduser()
with logfile.open("a") as f:
Expand All @@ -46,18 +48,21 @@ def log_wifi_loc(cadence_sec: float, mozilla_url: str, logfile: Path | None = No
sleep(cadence_sec)
continue

loc = get_loc_mozilla(dat, mozilla_url)
if url:
loc = get_loc_mozilla(dat, url)

if loc is None:
logging.warning(f"Did not get location from {len(dat)} BSSIDs")
sleep(cadence_sec)
continue
if loc is None:
logging.warning(f"Did not get location from {len(dat)} BSSIDs")
sleep(cadence_sec)
continue

stat = f'{loc["t"].isoformat(timespec="seconds")} {loc["lat"]} {loc["lng"]} {loc["accuracy"]:.1f} {loc["N"]:02d}'
print(stat)
stat = f'{loc["t"].isoformat(timespec="seconds")} {loc["lat"]} {loc["lng"]} {loc["accuracy"]:.1f} {loc["N"]:02d}'
print(stat)

if logfile:
with logfile.open("a") as f:
f.write(stat + "\n")
if logfile:
with logfile.open("a") as f:
f.write(stat + "\n")
else:
print(dat)

sleep(cadence_sec)

0 comments on commit 24dbec7

Please sign in to comment.