diff --git a/wifi_manager.py b/wifi_manager.py index ed92f9e..04a8133 100644 --- a/wifi_manager.py +++ b/wifi_manager.py @@ -83,7 +83,12 @@ def scan_wifi(): wifi_list.append({'ssid': ssid, 'signal': strength}) if len(wifi_list) == 15: break - + + # save wifi_list to file + with open('wifi_list.txt', 'w') as f: + for wifi in wifi_list: + f.write(f"{wifi['ssid']},{wifi['signal']}\n") + return wifi_list except subprocess.CalledProcessError as e: print(f"Error scanning for Wi-Fi networks: {e}") @@ -158,10 +163,6 @@ if __name__ == '__main__': print("----------------------------") wifi_list = scan_wifi() print("----------------------------") - # save wifi_list to file - with open('wifi_list.txt', 'w') as f: - for wifi in wifi_list: - f.write(f"{wifi['ssid']},{wifi['signal']}\n") restart_hotspot() # 启动 Flask 服务器