pipeline.py: a bit of tidying of the backfill command

This commit is contained in:
Peter Williams 2024-06-28 14:33:53 -04:00
Родитель 5e777c3031
Коммит 40cf920181
2 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -532,10 +532,12 @@ def _parse_record_file(stream, path):
def _emit_record(kind, fields, stream):
print(f"\n@{kind}", file=stream)
prev_had_blank_line = False
for key, value in fields.items():
if key in ("text", "credits"):
print(file=stream)
if not prev_had_blank_line:
print(file=stream)
for line in textwrap.wrap(
f"{key}> {value}",
@ -546,8 +548,10 @@ def _emit_record(kind, fields, stream):
print(line, file=stream)
print(file=stream)
prev_had_blank_line = True
else:
print(f"{key}: {value}", file=stream)
prev_had_blank_line = False
print("---", file=stream)

Просмотреть файл

@ -130,6 +130,10 @@ def backfill_impl(settings):
# Let's get going
n_tot = 0
n_already = 0
n_added = 0
for item in folder.children:
if not isinstance(item, Place):
continue
@ -137,10 +141,12 @@ def backfill_impl(settings):
place: Place = item
imgset = place.foreground_image_set
assert imgset is not None
n_tot += 1
# This should end with something like .../{feedname}/{uniq_id}/thumb.jpg
uniq_id = imgset.thumbnail_url.split("/")[-2]
if uniq_id in seen_ids:
n_already += 1
continue
# Generate records for the prep file
@ -165,15 +171,21 @@ def backfill_impl(settings):
if not text:
text = imgset.name
fields["text"] = text
fields["text"] = " ".join(text.strip().split())
fields["credits"] = imgset.credits
fields["wip"] = "yes"
prep_items.append(("corepipe_image", fields))
n_added += 1
with open(mgr._path("prep.txt"), "wt", encoding="utf-8") as f:
for kind, fields in prep_items:
_emit_record(kind, fields, f)
print(f"Processed {n_tot} Place records from the WTML file")
print(
f"(Re)wrote `{mgr._path('prep.txt')}` with {n_added} new entries; {n_already} already present"
)
# The "fetch" subcommand