codestyle
This commit is contained in:
parent
ab1e6a70fb
commit
b7b90083e6
@ -1,10 +1,12 @@
|
||||
import hashlib
|
||||
import logging
|
||||
import shutil
|
||||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
import zipfile
|
||||
from typing import Optional
|
||||
|
||||
import magic
|
||||
import tqdm
|
||||
from asgiref.sync import async_to_sync
|
||||
from celery import Task
|
||||
@ -166,9 +168,6 @@ def consume_file(
|
||||
|
||||
document = None
|
||||
|
||||
import magic
|
||||
import zipfile
|
||||
|
||||
mime_type = magic.from_file(input_doc.original_file, mime=True)
|
||||
if mime_type == "application/zip":
|
||||
with zipfile.ZipFile(input_doc.original_file, "r") as zip_ref:
|
||||
@ -181,13 +180,19 @@ def consume_file(
|
||||
# copy file (taken from zipfile's extract)
|
||||
try:
|
||||
source = zip_ref.open(member)
|
||||
target = open(os.path.join(input_doc.original_file.parent, filename), "wb")
|
||||
logger.info(f"extracting {filename} from zipfile {input_doc.original_file}")
|
||||
with source, target:
|
||||
shutil.copyfileobj(source, target)
|
||||
inputfile = input_doc.original_file
|
||||
with open(
|
||||
os.path.join(inputfile.parent, filename),
|
||||
"wb",
|
||||
) as f:
|
||||
logger.info(
|
||||
f"extracting {filename} from zipfile {inputfile}",
|
||||
)
|
||||
with source, f:
|
||||
shutil.copyfileobj(source, f)
|
||||
# continue with consumption if no barcode was found
|
||||
document = Consumer().try_consume_file(
|
||||
os.path.join(input_doc.original_file.parent, filename),
|
||||
os.path.join(inputfile.parent, filename),
|
||||
override_filename=overrides.filename,
|
||||
override_title=overrides.title,
|
||||
override_correspondent_id=overrides.correspondent_id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user