-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_configs.py
53 lines (46 loc) · 1.72 KB
/
setup_configs.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import json
from collections import OrderedDict
DB_FILE = "DBSettings.json"
PUSH_FILE = "PushSettings.json"
def get_push_settings():
push_dict = OrderedDict()
client_id = input("Enter Pushbullet client id: ").strip()
push_dict["client_id"] = client_id
client_secret = input("Enter Pushbullet client secret: ").strip()
push_dict["client_secret"] = client_secret
redirect_uri = input("Enter Pushbullet redirect URI: ").strip()
push_dict["redirect_uri"] = redirect_uri
with open(PUSH_FILE, 'w') as push_file:
push_file.write(json.dumps(push_dict, indent=4))
def get_db_settings():
db_dict = OrderedDict()
user = input("Enter database username: ").strip()
db_dict["username"] = user
password = input("Enter database password: ").strip()
db_dict["password"] = password
db_name = input("Please enter database name: ").strip()
db_dict["db"] = db_name
print(json.dumps(db_dict, indent=4))
with open(DB_FILE, 'w') as db_file:
db_file.write(json.dumps(db_dict, indent=4))
def get_settings():
if os.path.exists(DB_FILE):
os.remove(DB_FILE)
if os.path.exists(PUSH_FILE):
os.remove(PUSH_FILE)
get_db_settings()
get_push_settings()
def main():
if os.path.exists(DB_FILE) or os.path.exists(PUSH_FILE):
allowed = ['yes', 'no', 'y', 'n']
res = input("Do you want to override old files? ").lower()
while res not in allowed:
print("Please enter one of the following: {}".format(", ".join(allowed)))
res = input("Do you want to override old files? ").lower()
if res in ['yes', 'y']:
get_settings()
else:
get_settings()
if __name__ == '__main__':
main()