-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdcli.py
More file actions
69 lines (61 loc) · 2.25 KB
/
mdcli.py
File metadata and controls
69 lines (61 loc) · 2.25 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Mikan Cli Client"
)
parser.add_argument(
"action",
#help="action [known, search, add, updateanddownload, download, update, updatecover, setup, useradd, userreset, userdelete]"
help="action [setup]"
)
""" parser.add_argument(
"-s", "--serie",
metavar="SERIEID",
help="serie id"
)
parser.add_argument(
"-n", "--name",
metavar="SERIENAME",
help="serie name"
) """
args = parser.parse_args()
print(f"action: {args.action}")
""" print(f"serie id: {args.serie}")
print(f"serie name: {args.name}") """
if args.action == "setup":
print("\nMikan setup")
import configparser
import sqlite3
from getpass import getpass
from json import loads,dumps
from src.base import Base
configFile = Base().getInfo("configFile")
settings = Base().getInfo("settings")
print("\n")
config = configparser.ConfigParser(interpolation=None)
config.read(configFile)
for confGroup in config:
for confName in config[confGroup]:
i = input("Please input \""+confGroup+" - "+confName+"\" Now is \""+config.get(confGroup, confName).replace("'","")+"\": ")
config[confGroup][confName] = "'" + (i if i != "" else config.get(confGroup, confName).replace("'","")) + "'"
print("save as \""+config.get(confGroup, confName).replace("'","")+"\"")
with open(configFile, 'w') as configfile:
config.write(configfile)
print("\n")
userAll = loads(settings["webUser"]) if settings["webUser"] != "" and settings["webUser"] != None and settings["webUser"] != "[]" else {}
username = input("Please input Username: ")
while(username in userAll):
force = input("Already have this user, force reset Yes/No(default:No): ")
if force.lower() == "yes" or force.lower() == "y":
break
else:
username = input("Please input Username: ")
password = Base().hashPassword(getpass("Please input Password: "))
userAll[username] = password
db = sqlite3.connect(Base().getInfo("config")["db_location"])
db.execute('PRAGMA journal_mode=WAL;')
cursor = db.cursor()
cursor.execute("UPDATE `settings` SET `value` = ? WHERE key = ?", (dumps(userAll),"webUser",))
db.commit()
cursor.close()
db.close()