kopia lustrzana https://github.com/tayfunulu/WiFiManager
use with-statement for open()
rodzic
e4cda8a95a
commit
23af7385b0
5
main.py
5
main.py
|
@ -35,9 +35,8 @@ def check_connection():
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
if not wlan_sta.isconnected():
|
if not wlan_sta.isconnected():
|
||||||
# inside passwd file, there is a list of WiFi networks (CSV format)
|
# inside passwd file, there is a list of WiFi networks (CSV format)
|
||||||
f = open("passwd.dat")
|
with open("passwd.dat") as f:
|
||||||
data = f.readlines()
|
data = f.readlines()
|
||||||
f.close()
|
|
||||||
# Search WiFis in range
|
# Search WiFis in range
|
||||||
ssids_found = wlan_sta.scan()
|
ssids_found = wlan_sta.scan()
|
||||||
|
|
||||||
|
|
|
@ -106,17 +106,14 @@ def handle_configure(client, request):
|
||||||
<br><br>"""
|
<br><br>"""
|
||||||
send_response(client, response_footer)
|
send_response(client, response_footer)
|
||||||
try:
|
try:
|
||||||
fo = open("passwd.dat", "r")
|
with open("passwd.dat", "r") as fo:
|
||||||
ex_data = fo.read()
|
ex_data = fo.read()
|
||||||
fo.close()
|
|
||||||
fo = open("passwd.dat", "w")
|
|
||||||
ex_data = ssid + ";" + password + "\n" + ex_data
|
ex_data = ssid + ";" + password + "\n" + ex_data
|
||||||
fo.write(ex_data)
|
with open("passwd.dat", "w") as fo:
|
||||||
fo.close()
|
fo.write(ex_data)
|
||||||
except:
|
except:
|
||||||
fo = open("passwd.dat", "w")
|
with open("passwd.dat", "w") as fo:
|
||||||
fo.write(ssid + ";" + password + "\n")
|
fo.write(ssid + ";" + password + "\n")
|
||||||
fo.close()
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
response_footer = """
|
response_footer = """
|
||||||
|
|
Ładowanie…
Reference in New Issue