Browse Source

v3.6: 正则支持忽略出生行

Tinger 2 years ago
parent
commit
d5c336a593
1 changed files with 6 additions and 6 deletions
  1. 6 6
      blues/idc.py

+ 6 - 6
blues/idc.py

@@ -10,9 +10,9 @@ idc = Blueprint("idc", __name__, url_prefix="/idc")
 _MIN_SIZE = 46
 _MIN_SIZE = 46
 _EXCLUDE_CHAR = "中国CHINA *#★☆"
 _EXCLUDE_CHAR = "中国CHINA *#★☆"
 __face_ptn = re.compile(
 __face_ptn = re.compile(
-    r"[姓名]{0,2}(?P<name>.+?)[姓名]{0,2}"
+    r"[姓名]{0,2}(?P<name>.+?)[姓名]{0,2}"                            # 解决name在`姓名`之前,name字体较大
     r"[性别]{1,2}(?P<gender>[男女])民族(?P<nation>.+?)"
     r"[性别]{1,2}(?P<gender>[男女])民族(?P<nation>.+?)"
-    r"[出生]{1,2}(?P<year>\d{4})年(?P<month>\d+)月(?P<day>\d+)日"
+    r"([出生]{1,2}(?P<year>\d{4})年(?P<month>\d+)月(?P<day>\d+)日)?"  # 测试中出现该行有较大概率未被识别
     r"[住址]{1,2}(?P<addr>.+?)"
     r"[住址]{1,2}(?P<addr>.+?)"
     r"[公民身份号码]{1,6}(?P<idn>\d{17}[\dx])$",
     r"[公民身份号码]{1,6}(?P<idn>\d{17}[\dx])$",
     re.I
     re.I
@@ -29,16 +29,16 @@ def get_face_info(data_str: "str") -> "tuple[dict, bool]":
     res = {"name": "", "gender": "", "nation": "", "birth": {"year": "", "month": "", "day": ""}, "addr": "", "idn": ""}
     res = {"name": "", "gender": "", "nation": "", "birth": {"year": "", "month": "", "day": ""}, "addr": "", "idn": ""}
 
 
     if match := __face_ptn.match(data_str):
     if match := __face_ptn.match(data_str):
+        res["idn"] = match.group("idn")
         res["name"] = match.group("name")
         res["name"] = match.group("name")
         res["gender"] = match.group("gender")
         res["gender"] = match.group("gender")
         res["nation"] = match.group("nation")
         res["nation"] = match.group("nation")
         res["birth"] = {
         res["birth"] = {
-            "year": match.group("year"),
-            "month": match.group("month"),
-            "day": match.group("day")
+            "year": match.group("year") or res["idn"][6:10],
+            "month": match.group("month") or res["idn"][10:12],
+            "day": match.group("day") or res["idn"][12:14]
         }
         }
         res["addr"] = match.group("addr")
         res["addr"] = match.group("addr")
-        res["idn"] = match.group("idn")
         return res, True
         return res, True
 
 
     return res, False
     return res, False