Skip to content

Commit

Permalink
Add extra metadata and call task to add OCR
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Aug 12, 2024
1 parent 3c20d8b commit fcfafb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions readux_ingest_ecds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,15 @@ class Meta:
verbose_name_plural = "Amazon S3 Ingests"

def ingest(self):
metadata = metadata_from_file(self.metadata_spreadsheet.path)
rows = metadata_from_file(self.metadata_spreadsheet.path)

for pid in [row["pid"] for row in metadata]:
for row in rows:
pid = row["pid"]
manifest = create_manifest_from_pid(pid, self.image_server)
metadata = dict(row)
for key, value in metadata.items():
setattr(manifest, key, value)

manifest.collections.set(self.collections.all())
manifest.save()
local_ingest = Local.objects.create(
Expand Down Expand Up @@ -452,5 +457,12 @@ def ingest(self):
t_file.write(f"{image_file}\n")

local_ingest.create_canvases()
manifest.save()
from .tasks import add_ocr_task_local

if os.environ["DJANGO_ENV"] == "test":
add_ocr_task_local(str(local_ingest.id))
else:
add_ocr_task_local.delay(str(local_ingest.id))

self.delete()
5 changes: 3 additions & 2 deletions test_app/tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def create_pids(self, pid_count=1, image_count=1, include_pid_in_file=True):
pids = []
pid_file = os.path.join(self.fixture_path, self.fake.file_name(extension="csv"))
with open(pid_file, "w", encoding="utf-8") as t_file:
t_file.write("PID\n")
t_file.write("PID,Label\n")

for _ in range(pid_count):
pid = self.fake.isbn10()
with open(pid_file, "a", encoding="utf-8") as t_file:
t_file.write(f"{pid}\n")
t_file.write(f"{pid},{self.fake.name()}\n")
pids.append(pid)
self.create_source_images(
pid=pid, count=image_count, include_pid_in_file=include_pid_in_file
Expand Down Expand Up @@ -123,6 +123,7 @@ def test_s3_ingest_pid_not_in_filename(self):
]
assert Manifest.objects.filter(pid=pid).exists()
assert Manifest.objects.get(pid=pid).canvas_set.count() == 4
assert Manifest.objects.get(pid=pid).label is not None
assert len(ingested_images) == 4
assert len(ingested_ocr) == 4

Expand Down

0 comments on commit fcfafb7

Please sign in to comment.