15d73747 by 周伟奇

idcard script

1 parent 9e8023a0
...@@ -14,7 +14,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -14,7 +14,7 @@ class Command(BaseCommand, LoggerMixin):
14 14
15 def __init__(self): 15 def __init__(self):
16 super().__init__() 16 super().__init__()
17 self.sheet_names = ('AFC', 'HIL') 17 self.sheet_names = (consts.AFC_PREFIX, consts.HIL_PREFIX)
18 self.header = ('申请号', '身份证号', '民族', '时间戳') 18 self.header = ('申请号', '身份证号', '民族', '时间戳')
19 19
20 def add_arguments(self, parser): 20 def add_arguments(self, parser):
...@@ -53,34 +53,28 @@ class Command(BaseCommand, LoggerMixin): ...@@ -53,34 +53,28 @@ class Command(BaseCommand, LoggerMixin):
53 53
54 with open(log_path, 'r', encoding='utf-8') as fp: 54 with open(log_path, 'r', encoding='utf-8') as fp:
55 for line in fp: 55 for line in fp:
56 search_obj = re.search(r'[(.*)] [task=(.*)] [idcard=(.*)]', line) 56 search_obj = re.match(r'\[(.*)] \[task=(.*)] \[idcard=(.*)]', line)
57 task_str = search_obj.group(1) 57 idcard_str = search_obj.group(3)
58 license_summary = ast.literal_eval(search_obj.group(2)) 58 idcard_list = ast.literal_eval(idcard_str)
59 content_list = []
60 for idcard_dict in idcard_list:
61 nation = idcard_dict.get('民族')
62 if nation is None:
63 continue
64 if idcard_dict.get('类别') == '1':
65 continue
66 content_list.append((idcard_dict.get('公民身份号码'), nation))
67 if len(content_list) == 0:
68 continue
69
70 time_str = search_obj.group(1)
71 task_str = search_obj.group(2)
59 business_type, doc_id_str = task_str.split(consts.SPLIT_STR) 72 business_type, doc_id_str = task_str.split(consts.SPLIT_STR)
60 doc_id = int(doc_id_str)
61 doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc 73 doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc
62 application_id = doc_class.objects.filter(id=doc_id).values_list('application_id', flat=True) 74 application_id = doc_class.objects.filter(id=int(doc_id_str)).values_list('application_id', flat=True)
75
76 ws = wb.get_sheet_by_name(business_type)
77 for id_num, nation in content_list:
78 ws.append((application_id[0], id_num, nation, time_str))
63 79
64 for classify, (_, name, field_order, side_diff, _, _) in consts.LICENSE_ORDER:
65 license_list = license_summary.get(classify)
66 if not license_list:
67 continue
68 ws = wb.get_sheet_by_name(name)
69 for license_dict in license_list:
70 if classify == consts.IC_CLASSIFY and license_dict.get('类别') == '1': # 居住证处理
71 license_summary.setdefault(consts.RP_CLASSIFY, []).append(license_dict)
72 continue
73 if side_diff:
74 key, field_order_yes, field_order_no = consts.FIELD_ORDER_MAP.get(classify)
75 field_order = field_order_yes if key in license_dict else field_order_no
76 all_value = []
77 for search_field, write_field in field_order:
78 if write_field is None:
79 continue
80 field_value = license_dict.get(search_field, '')
81 if isinstance(field_value, list):
82 all_value.append('\n'.join(field_value))
83 else:
84 all_value.append(field_value)
85 ws.append((application_id[0], *all_value))
86 wb.save(excel_path) 80 wb.save(excel_path)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!