fix bug
Showing
4 changed files
with
16 additions
and
16 deletions
1 | import os | 1 | import os |
2 | import time | 2 | import time |
3 | import json | ||
3 | import signal | 4 | import signal |
4 | import asyncio | 5 | import asyncio |
5 | import aiohttp | 6 | import aiohttp |
... | @@ -197,7 +198,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -197,7 +198,7 @@ class Command(BaseCommand, LoggerMixin): |
197 | async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session: | 198 | async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session: |
198 | async with session.post(url, data=json_data) as response: | 199 | async with session.post(url, data=json_data) as response: |
199 | if response.status == 200: | 200 | if response.status == 200: |
200 | return await response.json() | 201 | return await response.text() |
201 | 202 | ||
202 | @staticmethod | 203 | @staticmethod |
203 | async def fetch_bc_name_result(url, json_data): | 204 | async def fetch_bc_name_result(url, json_data): |
... | @@ -245,13 +246,15 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -245,13 +246,15 @@ class Command(BaseCommand, LoggerMixin): |
245 | raise Exception('ocr 2 error, img_path={0}'.format(img_path)) | 246 | raise Exception('ocr 2 error, img_path={0}'.format(img_path)) |
246 | else: | 247 | else: |
247 | # 识别结果 | 248 | # 识别结果 |
249 | ocr_res_2 = json.loads(ocr_res_2) | ||
248 | self.cronjob_log.info('{0} [ocr_2 result] [img={1}] [res={2}]'.format( | 250 | self.cronjob_log.info('{0} [ocr_2 result] [img={1}] [res={2}]'.format( |
249 | self.log_base, img_path, ocr_res_2)) | 251 | self.log_base, img_path, ocr_res_2)) |
250 | if classify == consts.BC_CLASSIFY: | 252 | if classify == consts.BC_CLASSIFY: |
251 | name = '有' | 253 | name = '有' |
252 | json_data_1['card_res'] = ocr_res_2 | 254 | json_data_1['card_res'] = ocr_res_2 |
253 | card_name_res = await self.fetch_bc_name_result(self.ocr_url_3, json_data_1) | 255 | card_name_res = await self.fetch_bc_name_result(self.ocr_url_3, json_data_1) |
254 | if card_name_res.get('code') == 1 and card_name_res.get('data', {}).get('is_exists_name') == 0: | 256 | if isinstance(card_name_res, dict) and \ |
257 | card_name_res.get('data', {}).get('is_exists_name') == 0: | ||
255 | name = '无' | 258 | name = '无' |
256 | ocr_res_2['Name'] = name | 259 | ocr_res_2['Name'] = name |
257 | self.license2_process(ocr_res_2, license_summary, pid, classify, skip_img, img_path) | 260 | self.license2_process(ocr_res_2, license_summary, pid, classify, skip_img, img_path) |
... | @@ -521,7 +524,6 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -521,7 +524,6 @@ class Command(BaseCommand, LoggerMixin): |
521 | # EDMS异常:下载异常-->回队列-->邮件;上传异常-->重新上传队列-->邮件 | 524 | # EDMS异常:下载异常-->回队列-->邮件;上传异常-->重新上传队列-->邮件 |
522 | # 算法异常:第一道异常-->识别失败-->邮件;第二道异常-->识别失败-->邮件 | 525 | # 算法异常:第一道异常-->识别失败-->邮件;第二道异常-->识别失败-->邮件 |
523 | # TODO OCR接口调用重试 | 526 | # TODO OCR接口调用重试 |
524 | # TODO 数据库断联问题 | ||
525 | def handle(self, *args, **kwargs): | 527 | def handle(self, *args, **kwargs): |
526 | sleep_second = int(conf.SLEEP_SECOND) | 528 | sleep_second = int(conf.SLEEP_SECOND) |
527 | max_sleep_second = int(conf.MAX_SLEEP_SECOND) | 529 | max_sleep_second = int(conf.MAX_SLEEP_SECOND) | ... | ... |
... | @@ -24,6 +24,7 @@ class UploadDocRecords(models.Model): | ... | @@ -24,6 +24,7 @@ class UploadDocRecords(models.Model): |
24 | class Meta: | 24 | class Meta: |
25 | managed = False | 25 | managed = False |
26 | db_table = 'upload_doc_records' | 26 | db_table = 'upload_doc_records' |
27 | situ_db_label = 'afc' | ||
27 | 28 | ||
28 | 29 | ||
29 | class HILDoc(models.Model): | 30 | class HILDoc(models.Model): | ... | ... |
... | @@ -251,17 +251,9 @@ class BSWorkbook(Workbook): | ... | @@ -251,17 +251,9 @@ class BSWorkbook(Workbook): |
251 | ) | 251 | ) |
252 | return metadata_rows | 252 | return metadata_rows |
253 | 253 | ||
254 | def create_meta_sheet(self, card): | ||
255 | if self.worksheets[0].title == 'Sheet': | ||
256 | ms = self.worksheets[0] | ||
257 | ms.title = '{0}({1})'.format(self.meta_sheet_title, card[-6:]) | ||
258 | else: | ||
259 | ms = self.create_sheet('{0}({1})'.format(self.meta_sheet_title, card[-6:])) | ||
260 | return ms | ||
261 | |||
262 | def build_meta_sheet(self, card, confidence, code, print_time, start_date, end_date): | 254 | def build_meta_sheet(self, card, confidence, code, print_time, start_date, end_date): |
263 | metadata_rows = self.build_metadata_rows(confidence, code, print_time, start_date, end_date) | 255 | metadata_rows = self.build_metadata_rows(confidence, code, print_time, start_date, end_date) |
264 | ms = self.create_meta_sheet(card) | 256 | ms = self.create_sheet('{0}({1})'.format(self.meta_sheet_title, card[-6:])) |
265 | for row in metadata_rows: | 257 | for row in metadata_rows: |
266 | ms.append(row) | 258 | ms.append(row) |
267 | return ms | 259 | return ms |
... | @@ -517,7 +509,12 @@ class BSWorkbook(Workbook): | ... | @@ -517,7 +509,12 @@ class BSWorkbook(Workbook): |
517 | for img_tuple in skip_img: | 509 | for img_tuple in skip_img: |
518 | ws.append(img_tuple) | 510 | ws.append(img_tuple) |
519 | 511 | ||
512 | def remove_base_sheet(self): | ||
513 | if len(self.sheetnames) > 1: | ||
514 | self.remove(self.get_sheet_by_name('Sheet')) | ||
515 | |||
520 | def rebuild(self, bs_summary, license_summary, skip_img, document_scheme): | 516 | def rebuild(self, bs_summary, license_summary, skip_img, document_scheme): |
521 | self.bs_rebuild(bs_summary) | 517 | self.bs_rebuild(bs_summary) |
522 | self.license_rebuild(license_summary, document_scheme) | 518 | self.license_rebuild(license_summary, document_scheme) |
523 | self.skip_img_sheet(skip_img) | 519 | self.skip_img_sheet(skip_img) |
520 | self.remove_base_sheet() | ... | ... |
... | @@ -88,10 +88,10 @@ priority_doc_args = { | ... | @@ -88,10 +88,10 @@ priority_doc_args = { |
88 | 88 | ||
89 | 89 | ||
90 | class UploadDocView(GenericView, DocHandler): | 90 | class UploadDocView(GenericView, DocHandler): |
91 | permission_classes = [] | 91 | # permission_classes = [] |
92 | authentication_classes = [] | 92 | # authentication_classes = [] |
93 | # permission_classes = [IsAuthenticated] | 93 | permission_classes = [IsAuthenticated] |
94 | # authentication_classes = [OAuth2AuthenticationWithUser] | 94 | authentication_classes = [OAuth2AuthenticationWithUser] |
95 | # required_scopes = ['write'] | 95 | # required_scopes = ['write'] |
96 | 96 | ||
97 | # 上传(接收)文件接口 | 97 | # 上传(接收)文件接口 | ... | ... |
-
Please register or sign in to post a comment