9f8a7658 by 周伟奇

fix bug

1 parent 623ca8c8
import os
import time
import json
import signal
import asyncio
import aiohttp
......@@ -197,7 +198,7 @@ class Command(BaseCommand, LoggerMixin):
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
async with session.post(url, data=json_data) as response:
if response.status == 200:
return await response.json()
return await response.text()
@staticmethod
async def fetch_bc_name_result(url, json_data):
......@@ -245,13 +246,15 @@ class Command(BaseCommand, LoggerMixin):
raise Exception('ocr 2 error, img_path={0}'.format(img_path))
else:
# 识别结果
ocr_res_2 = json.loads(ocr_res_2)
self.cronjob_log.info('{0} [ocr_2 result] [img={1}] [res={2}]'.format(
self.log_base, img_path, ocr_res_2))
if classify == consts.BC_CLASSIFY:
name = '有'
json_data_1['card_res'] = ocr_res_2
card_name_res = await self.fetch_bc_name_result(self.ocr_url_3, json_data_1)
if card_name_res.get('code') == 1 and card_name_res.get('data', {}).get('is_exists_name') == 0:
if isinstance(card_name_res, dict) and \
card_name_res.get('data', {}).get('is_exists_name') == 0:
name = '无'
ocr_res_2['Name'] = name
self.license2_process(ocr_res_2, license_summary, pid, classify, skip_img, img_path)
......@@ -521,7 +524,6 @@ class Command(BaseCommand, LoggerMixin):
# EDMS异常:下载异常-->回队列-->邮件;上传异常-->重新上传队列-->邮件
# 算法异常:第一道异常-->识别失败-->邮件;第二道异常-->识别失败-->邮件
# TODO OCR接口调用重试
# TODO 数据库断联问题
def handle(self, *args, **kwargs):
sleep_second = int(conf.SLEEP_SECOND)
max_sleep_second = int(conf.MAX_SLEEP_SECOND)
......
......@@ -24,6 +24,7 @@ class UploadDocRecords(models.Model):
class Meta:
managed = False
db_table = 'upload_doc_records'
situ_db_label = 'afc'
class HILDoc(models.Model):
......
......@@ -251,17 +251,9 @@ class BSWorkbook(Workbook):
)
return metadata_rows
def create_meta_sheet(self, card):
if self.worksheets[0].title == 'Sheet':
ms = self.worksheets[0]
ms.title = '{0}({1})'.format(self.meta_sheet_title, card[-6:])
else:
ms = self.create_sheet('{0}({1})'.format(self.meta_sheet_title, card[-6:]))
return ms
def build_meta_sheet(self, card, confidence, code, print_time, start_date, end_date):
metadata_rows = self.build_metadata_rows(confidence, code, print_time, start_date, end_date)
ms = self.create_meta_sheet(card)
ms = self.create_sheet('{0}({1})'.format(self.meta_sheet_title, card[-6:]))
for row in metadata_rows:
ms.append(row)
return ms
......@@ -517,7 +509,12 @@ class BSWorkbook(Workbook):
for img_tuple in skip_img:
ws.append(img_tuple)
def remove_base_sheet(self):
if len(self.sheetnames) > 1:
self.remove(self.get_sheet_by_name('Sheet'))
def rebuild(self, bs_summary, license_summary, skip_img, document_scheme):
self.bs_rebuild(bs_summary)
self.license_rebuild(license_summary, document_scheme)
self.skip_img_sheet(skip_img)
self.remove_base_sheet()
......
......@@ -88,10 +88,10 @@ priority_doc_args = {
class UploadDocView(GenericView, DocHandler):
permission_classes = []
authentication_classes = []
# permission_classes = [IsAuthenticated]
# authentication_classes = [OAuth2AuthenticationWithUser]
# permission_classes = []
# authentication_classes = []
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
# required_scopes = ['write']
# 上传(接收)文件接口
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!