-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·57 lines (35 loc) · 1.16 KB
/
main.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
#!/usr/bin/env python3
import argparse
import logging
TCID_LENGTH = 11
def validator(tc_id: str) -> bool:
if len(tc_id) != TCID_LENGTH:
logging.warning("TC id length is not 11. Length: %d" % len(tc_id))
return False
if tc_id[0] == '0':
logging.warning("First digit cannot be 0.")
return False
id_arr = [int(d) for d in list(tc_id)]
d9 = (7 * (sum(id_arr[:-2][0::2])) - sum(id_arr[:-2][1::2])) % 10
if d9 != id_arr[9]:
logging.warning("Not pass 10th digit validation.")
return False
d10 = sum(id_arr[:-1]) % 10
if d10 != id_arr[10]:
logging.warning("Not pass 11th digit validation.")
return False
return True
def get_tc_id():
parser = argparse.ArgumentParser(description="")
parser.add_argument("tc_id", type=str, help='Set TC id')
args = parser.parse_args()
return args.tc_id
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
logging.info("TC id validator")
tc_id = get_tc_id()
result = validator(tc_id)
if result:
logging.info("%s is valid." % tc_id)
else:
logging.info("%s is not valid." % tc_id)