-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
33 lines (29 loc) · 786 Bytes
/
db.py
File metadata and controls
33 lines (29 loc) · 786 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
30
31
32
33
import os
import json
if not os.path.exists('db.json'):
db = {'tokens': [],
'id': {},
'tg': {},
'ds': {},
'mine': {},
'nick': {}}
js = json.dumps(db, indent=2)
with open("db.json", "w") as outfile:
outfile.write(js)
print('Created new db.json')
if not os.path.exists('conf.json'):
db = {'api_token': 'None',
'tg_token': 'None',
'ds_token': 'None'}
js = json.dumps(db, indent=2)
with open("conf.json", "w") as outfile:
outfile.write(js)
print('Created new conf.json')
def read(file = 'db.json'):
with open(file, "r", encoding="utf-8") as openfile:
db = json.load(openfile)
return db
def write(db, file = 'db.json'):
js = json.dumps(db, indent=2, ensure_ascii=False)
with open(file, "w", encoding="utf-8") as outfile:
outfile.write(js)