-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
29 lines (23 loc) · 712 Bytes
/
Copy pathconfig.py
File metadata and controls
29 lines (23 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
class Config:
def __init__(self, ssid, password):
self.ssid = ssid
self.password = password
self.exists = True
def asJson(self):
return json.dumps({"ssid": self.ssid, "password": self.password})
@classmethod
def read(cls, filename):
try:
f = open(filename)
except OSError:
c = Config('', '')
c.exists = False
return c
configDictionary = json.loads(f.read())
f.close()
return Config(configDictionary.get('ssid'), configDictionary.get('password'))
def write(self, filename):
f = open(filename, "w")
f.write(self.asJson())
f.close()