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
|
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File : generateID.py
@Time : 2020/11/08 10:35:09
@Author : Kyomotoi
@Contact : [email protected]
@Github : https://github.com/Kyomotoi
@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
'''
__author__ = 'kyomotoi'
import os
import json
import random
from pathlib import Path
from zipfile import PyZipFile
from typing import Tuple, Dict, List
FILE = Path('.') / 'ATRI' / 'plguins' / 'plugin_utils' / 'main.bin'
def infoID() -> Tuple[Dict[str, List[str]], Dict[str, str]]:
with PyZipFile(os.path.abspath(FILE), "r") as zipFile:
with zipFile.open("name.json", "r") as f:
name = json.loads(f.read().decode())
with zipFile.open("area.json", "r") as f:
area = json.loads(f.read().decode())
return name, area
def numberID(area: int, sex: int, birth: int) -> str:
def checkSum(fullCode: str) -> int or str:
assert len(fullCode) == 17
checkSum = sum([((1 << (17 - i)) % 11) * int(fullCode[i])
for i in range(0, 17)])
checkDigit = (12 - (checkSum % 11)) % 11
if checkDigit < 10:
return checkDigit
else:
return "X" # type: ignore
orderCode = str(random.randint(10, 99))
sexCode = str(random.randrange(sex, 10, step=2))
fullCode = str(area) + str(birth) + str(orderCode) + str(sexCode)
fullCode += str(checkSum(fullCode))
return fullCode
|