-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileIO.py
41 lines (26 loc) · 798 Bytes
/
fileIO.py
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
30
31
32
33
34
35
36
37
38
import json
PATH = "Persistant/config.json"
def createConfig():
'''Creates a default, blank configuration file.'''
dict = {
"userID": 0,
"sessionToken": "",
"apiToken": "",
"bearerToken": ""
}
writeConfig(dict)
def writeConfig(dict):
'''Takes a dictionary and writes it to the configuration file.'''
config = open(PATH, "w")
config.write(json.dumps(dict, indent=4))
config.close()
def openConfig():
'''Opens the configuration file, creates one if it does not exist.'''
try:
jsonObj = open(PATH, "x")
jsonObj.close()
createConfig()
jsonObj = open(PATH)
except FileExistsError:
jsonObj = open(PATH)
return json.load(jsonObj)