use f-strings and double quotes in gps plugin
This commit is contained in:
parent
3efa3a935a
commit
69597103b5
@ -9,41 +9,43 @@ from pwnagotchi.ui.view import BLACK
|
|||||||
|
|
||||||
|
|
||||||
class GPS(plugins.Plugin):
|
class GPS(plugins.Plugin):
|
||||||
__author__ = 'evilsocket@gmail.com'
|
__author__ = "evilsocket@gmail.com"
|
||||||
__version__ = '1.0.0'
|
__version__ = "1.0.0"
|
||||||
__license__ = 'GPL3'
|
__license__ = "GPL3"
|
||||||
__description__ = 'Save GPS coordinates whenever an handshake is captured.'
|
__description__ = "Save GPS coordinates whenever an handshake is captured."
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
|
|
||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
logging.info("gps plugin loaded for %s" % self.options['device'])
|
logging.info(f"gps plugin loaded for {self.options['device']}")
|
||||||
|
|
||||||
def on_ready(self, agent):
|
def on_ready(self, agent):
|
||||||
if os.path.exists(self.options['device']):
|
if os.path.exists(self.options["device"]):
|
||||||
logging.info("enabling bettercap's gps module for %s" % self.options['device'])
|
logging.info(
|
||||||
|
f"enabling bettercap's gps module for {self.options['device']}"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
agent.run('gps off')
|
agent.run("gps off")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
agent.run('set gps.device %s' % self.options['device'])
|
agent.run(f"set gps.device {self.options['device']}")
|
||||||
agent.run('set gps.baudrate %d' % self.options['speed'])
|
agent.run(f"set gps.baudrate {self.options['speed']}")
|
||||||
agent.run('gps on')
|
agent.run("gps on")
|
||||||
self.running = True
|
self.running = True
|
||||||
else:
|
else:
|
||||||
logging.warning('no GPS detected')
|
logging.warning("no GPS detected")
|
||||||
|
|
||||||
def on_handshake(self, agent, filename, access_point, client_station):
|
def on_handshake(self, agent, filename, access_point, client_station):
|
||||||
if self.running:
|
if self.running:
|
||||||
info = agent.session()
|
info = agent.session()
|
||||||
self.coordinates = info['gps']
|
self.coordinates = info["gps"]
|
||||||
gps_filename = filename.replace('.pcap', '.gps.json')
|
gps_filename = filename.replace(".pcap", ".gps.json")
|
||||||
|
|
||||||
logging.info("saving GPS to %s (%s)" % (gps_filename, self.coordinates))
|
logging.info(f"saving GPS to {gps_filename} ({self.coordinates})")
|
||||||
with open(gps_filename, 'w+t') as fp:
|
with open(gps_filename, "w+t") as fp:
|
||||||
json.dump(self.coordinates, fp)
|
json.dump(self.coordinates, fp)
|
||||||
|
|
||||||
def on_ui_setup(self, ui):
|
def on_ui_setup(self, ui):
|
||||||
@ -98,10 +100,10 @@ class GPS(plugins.Plugin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_ui_update(self, ui):
|
def on_ui_update(self, ui):
|
||||||
if self.coordinates and all([
|
# avoid 0.000... measurements
|
||||||
# avoid 0.000... measurements
|
if self.coordinates and all(
|
||||||
self.coordinates["Latitude"], self.coordinates["Longitude"]
|
[self.coordinates["Latitude"], self.coordinates["Longitude"]]
|
||||||
]):
|
):
|
||||||
ui.set("latitude", f"{self.coordinates['Latitude']:.4f}")
|
ui.set("latitude", f"{self.coordinates['Latitude']:.4f}")
|
||||||
ui.set("longitude", f" {self.coordinates['Longitude']:.4f}")
|
ui.set("longitude", f" {self.coordinates['Longitude']:.4f}")
|
||||||
ui.set("altitude", f" {self.coordinates['Altitude']:.1f}m")
|
ui.set("altitude", f" {self.coordinates['Altitude']:.1f}m")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user