This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnum.py
110 lines (105 loc) · 3.62 KB
/
num.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import fsdcert
cert = fsdcert.cert()
def check(string: str, mode=None):
for word in ["'", '"', ";"]:
if word in string:
return False
if mode == "callsign":
if not len(string) == 7:
return False
if (
not string[0:3].isalpha()
or not string[0:3].isupper()
or not string[3:7].isdigit()
):
return False
elif mode == "level":
try:
intstr = int(string)
except ValueError:
return False
if intstr < 0 or intstr > 12:
return False
return True
while True:
oper = input("请选择操作(C新建呼号 M更改信息 D删除呼号 I查询信息): ")
if not oper in ["C", "M", "D", "I"]:
print("错误的选择!")
continue
break
if oper == "C":
while True:
callsign = input("呼号: ")
if not check(callsign, mode="callsign"):
print("输入不正确!")
continue
if input(f"呼号是: {callsign} 要重新输入吗(Y确认呼号, 任意按键重新输入)? ") == "Y":
break
if callsign in cert:
print("呼号已存在!")
raise SystemExit
while True:
password = input("密码: ")
if not check(password):
print("输入不正确!")
continue
if input(f"密码是: {password} 要重新输入吗(Y确认密码, 任意按键重新输入)? ") == "Y":
break
cert[callsign] = {"password": password, "level": 1}
elif oper == "M":
while True:
callsign = input("呼号: ")
if not check(callsign, mode="callsign"):
print("输入不正确!")
continue
if input(f"呼号是: {callsign} 要重新输入吗(Y确认呼号, 任意按键重新输入)? ") == "Y":
break
if not callsign in cert:
print("呼号不存在!")
raise SystemExit
while True:
oper = input("更改密码或权限(P密码, L权限)? ")
if not oper in ["P", "L"]:
print("错误的选择!")
continue
break
if oper == "P":
while True:
password = input("密码: ")
if not check(password):
print("输入不正确!")
continue
if input(f"密码是: {password} 要重新输入吗(Y确认密码, 任意按键重新输入)? ") == "Y":
break
cert[callsign] = {"password": password}
elif oper == "L":
while True:
level = input("权限: ")
if not check(level, mode="level"):
print("输入不正确!")
continue
if input(f"权限是: {level} 要重新输入吗(Y确认密码, 任意按键重新输入)? ") == "Y":
break
cert[callsign] = {"level": int(level)}
elif oper == "D":
while True:
callsign = input("呼号: ")
if not check(callsign, mode="callsign"):
print("输入不正确!")
continue
if input(f"呼号是: {callsign} 要重新输入吗(Y确认呼号, 任意按键重新输入)? ") == "Y":
break
del cert[callsign]
elif oper == "I":
while True:
callsign = input("呼号: ")
if not check(callsign, mode="callsign"):
print("输入不正确!")
continue
if input(f"呼号是: {callsign} 要重新输入吗(Y确认呼号, 任意按键重新输入)? ") == "Y":
break
if not callsign in cert:
print("呼号不存在!")
raise SystemExit
info = cert[callsign]
print(f"等级: {info['level']}, 密码: {info['password']}")