MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / cache_wifi_scan

Method cache_wifi_scan

db_manager.py:1448–1511  ·  view source on GitHub ↗

Cache WiFi scan results to reduce expensive nmcli rescan calls. Args: networks: List of network dicts with ssid, signal, security, etc.

(self, networks: List[Dict[str, Any]])

Source from the content-addressed store, hash-verified

1446 logger.info(f"Exported {len(hosts)} hosts to {csv_path}")
1447 return True
1448
1449 except Exception as e:
1450 logger.error(f"Failed to export to CSV: {e}")
1451 return False
1452
1453
1454 # ============================================================================
1455 # WIFI MANAGEMENT METHODS
1456 # ============================================================================
1457
1458 def cache_wifi_scan(self, networks: List[Dict[str, Any]]):
1459 """
1460 Cache WiFi scan results to reduce expensive nmcli rescan calls.
1461
1462 Args:
1463 networks: List of network dicts with ssid, signal, security, etc.
1464 """
1465 try:
1466 with self.get_connection() as conn:
1467 cursor = conn.cursor()
1468 timestamp = datetime.now()
1469
1470 for network in networks:
1471 ssid = network.get('ssid', '').strip()
1472 if not ssid or network.get('instruction'): # Skip instruction entries
1473 continue
1474
1475 # Check if network exists
1476 cursor.execute("""
1477 SELECT scan_count FROM wifi_scan_cache WHERE ssid = ?
1478 """, (ssid,))
1479 row = cursor.fetchone()
1480
1481 if row:
1482 # Update existing entry
1483 scan_count = row[0] + 1
1484 cursor.execute("""
1485 UPDATE wifi_scan_cache
1486 SET signal = ?,
1487 security = ?,
1488 last_seen = ?,
1489 scan_count = ?,
1490 is_known = ?,
1491 has_system_profile = ?
1492 WHERE ssid = ?
1493 """, (
1494 network.get('signal', 0),
1495 network.get('security', ''),
1496 timestamp,
1497 scan_count,
1498 1 if network.get('known', False) else 0,
1499 1 if network.get('has_system_profile', False) else 0,
1500 ssid
1501 ))
1502 else:
1503 # Insert new entry
1504 cursor.execute("""
1505 INSERT INTO wifi_scan_cache

Callers 1

scan_networksMethod · 0.80

Calls 8

get_connectionMethod · 0.95
cursorMethod · 0.80
commitMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
getMethod · 0.45
executeMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected