forked from Dawnnnnnn/bilibili-live-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configloader.py
51 lines (41 loc) · 1.76 KB
/
configloader.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
import configparser
import codecs
def load_bilibili(file):
cf_bilibili = configparser.ConfigParser()
cf_bilibili.optionxform = str
cf_bilibili.read_file(codecs.open(file, "r", "utf8"))
dic_bilibili = cf_bilibili._sections
dic_nomalised_bilibili = dic_bilibili['normal'].copy()
dic_nomalised_bilibili['saved-session'] = dic_bilibili['saved-session'].copy()
dic_nomalised_bilibili['account'] = dic_bilibili['account'].copy()
if dic_nomalised_bilibili['account']['username']:
pass
else:
username = input("# 输入帐号: ")
password = input("# 输入密码: ")
cf_bilibili.set('account', 'username', username)
cf_bilibili.set('account', 'password', password)
cf_bilibili.write(codecs.open(file, "w+", "utf8"))
dic_nomalised_bilibili['account']['username'] = username
dic_nomalised_bilibili['account']['password'] = password
dic_bilibili_type = dic_bilibili['types']
# str to int
for i in dic_bilibili_type['int'].split():
dic_nomalised_bilibili[i] = int(dic_bilibili['normal'][i])
for i in dic_bilibili.keys():
# print(i)
if i[0:3] == 'dic':
dic_nomalised_bilibili[i[4:]] = dic_bilibili[i]
return dic_nomalised_bilibili
def load_user(file):
cf_user = configparser.ConfigParser()
cf_user.read_file(codecs.open(file, "r", "utf8"))
dic_user = cf_user._sections
return dic_user
def write2bilibili(dic):
cf_bilibili = configparser.ConfigParser(interpolation=None)
cf_bilibili.optionxform = str
cf_bilibili.read_file(codecs.open("conf/bilibili.conf", "r", "utf8"))
for i in dic.keys():
cf_bilibili.set('saved-session', i, dic[i])
cf_bilibili.write(codecs.open("conf/bilibili.conf", "w+", "utf8"))