-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
38 lines (33 loc) · 1.08 KB
/
config.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
import os
try:
#settings configuration
token = ""
while len(token) < 5:
token = input("Enter the Bot Token: ")
if len(token) < 5:
print("Bot token is required for the bot to work")
#make directory for the file
try:
print("Making config folder")
os.mkdir("config")
except FileExistsError:
print("Folder already exists, continuing")
except all:
print("An error has occcured, please try again later.")
os.__exit()
#prepare dictionary for file config
config = {"TOKEN":token}
#prepare JSON to write to file (chosen over json.dump for user friendliness)
formatJson = json.dumps(config, indent=4)
try:
with open("config/cfg.json", "w+") as file:
print("Attempting to write config file \"config/cfg.json\"")
file.write(formatJson)
file.close()
print("File written successfully")
except all:
print("An error has occurred")
os.__exit()
except KeyboardInterrupt:
print("Keyboard Interrupt - Ending config")