fix idcard daily
Showing
1 changed file
with
20 additions
and
11 deletions
... | @@ -2,7 +2,7 @@ import re | ... | @@ -2,7 +2,7 @@ import re |
2 | import os | 2 | import os |
3 | import ast | 3 | import ast |
4 | import datetime | 4 | import datetime |
5 | from openpyxl import Workbook | 5 | from openpyxl import Workbook, load_workbook |
6 | from django.core.management import BaseCommand | 6 | from django.core.management import BaseCommand |
7 | from settings import conf | 7 | from settings import conf |
8 | from common.mixins import LoggerMixin | 8 | from common.mixins import LoggerMixin |
... | @@ -48,15 +48,26 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -48,15 +48,26 @@ class Command(BaseCommand, LoggerMixin): |
48 | print('log_path not exists') | 48 | print('log_path not exists') |
49 | return | 49 | return |
50 | 50 | ||
51 | wb_afc = Workbook() | 51 | afc_excel_path = os.path.join(afc_excel_dir, 'idcard_{0}.xlsx'.format(date_str)) |
52 | ws_afc = wb_afc.create_sheet(self.sheet_name) | 52 | hil_excel_path = os.path.join(hil_excel_dir, 'idcard_{0}.xlsx'.format(date_str)) |
53 | ws_afc.append(self.header) | ||
54 | wb_afc.remove(wb_afc.get_sheet_by_name('Sheet')) | ||
55 | 53 | ||
56 | wb_hil = Workbook() | 54 | if os.path.isfile(afc_excel_path): |
57 | ws_hil = wb_hil.create_sheet(self.sheet_name) | 55 | wb_afc = load_workbook(afc_excel_path) |
58 | ws_hil.append(self.header) | 56 | ws_afc = wb_afc.get_sheet_by_name(self.sheet_name) |
59 | wb_hil.remove(wb_hil.get_sheet_by_name('Sheet')) | 57 | else: |
58 | wb_afc = Workbook() | ||
59 | ws_afc = wb_afc.create_sheet(self.sheet_name) | ||
60 | ws_afc.append(self.header) | ||
61 | wb_afc.remove(wb_afc.get_sheet_by_name('Sheet')) | ||
62 | |||
63 | if os.path.isfile(hil_excel_path): | ||
64 | wb_hil = load_workbook(hil_excel_path) | ||
65 | ws_hil = wb_hil.get_sheet_by_name(self.sheet_name) | ||
66 | else: | ||
67 | wb_hil = Workbook() | ||
68 | ws_hil = wb_hil.create_sheet(self.sheet_name) | ||
69 | ws_hil.append(self.header) | ||
70 | wb_hil.remove(wb_hil.get_sheet_by_name('Sheet')) | ||
60 | 71 | ||
61 | with open(log_path, 'r', encoding='utf-8') as fp: | 72 | with open(log_path, 'r', encoding='utf-8') as fp: |
62 | for line in fp: | 73 | for line in fp: |
... | @@ -87,7 +98,5 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -87,7 +98,5 @@ class Command(BaseCommand, LoggerMixin): |
87 | for id_num, nation in content_list: | 98 | for id_num, nation in content_list: |
88 | ws_afc.append((application_id[0], id_num, nation, time_str)) | 99 | ws_afc.append((application_id[0], id_num, nation, time_str)) |
89 | 100 | ||
90 | afc_excel_path = os.path.join(afc_excel_dir, 'idcard_{0}.xlsx'.format(date_str)) | ||
91 | hil_excel_path = os.path.join(hil_excel_dir, 'idcard_{0}.xlsx'.format(date_str)) | ||
92 | wb_afc.save(afc_excel_path) | 101 | wb_afc.save(afc_excel_path) |
93 | wb_hil.save(hil_excel_path) | 102 | wb_hil.save(hil_excel_path) | ... | ... |
-
Please register or sign in to post a comment