Skip to content

Commit

Permalink
fix: handle (and clean) html narrative minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Feb 15, 2024
1 parent 683915f commit 96398b6
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions ietf/meeting/management/commands/import_iesg_minutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def handle(self, *args, **options):
meeting_times = set()
for file_prefix in ["minutes", "narrative"]:
paths = list(minutes_dir.glob(f"[12][09][0129][0-9]/{file_prefix}*.txt"))
paths.extend(
list(minutes_dir.glob(f"[12][09][0129][0-9]/{file_prefix}*.html"))
)
for path in paths:
s = date_re.search(path.name)
if s:
Expand Down Expand Up @@ -198,9 +201,11 @@ def handle(self, *args, **options):
group_id=2, # The IESG group
type_id="regular",
purpose_id="regular",
name=f"IETF {bof_coord_data[dt].meeting_number} BOF Coordination Call"
if dt in bof_times
else "Formal Telechat",
name=(
f"IETF {bof_coord_data[dt].meeting_number} BOF Coordination Call"
if dt in bof_times
else "Formal Telechat"
),
)
SchedulingEvent.objects.create(
session=session,
Expand Down Expand Up @@ -259,15 +264,25 @@ def handle(self, *args, **options):
source_file_prefix = (
"minutes" if type_id == "minutes" else "narrative-minutes"
)
source = (
txt_source = (
minutes_dir
/ f"{dt.year}"
/ f"{source_file_prefix}-{dt:%Y-%m-%d}.txt"
)
if source.exists():
html_source = (
minutes_dir
/ f"{dt.year}"
/ f"{source_file_prefix}-{dt:%Y-%m-%d}.html"
)
if txt_source.exists() and html_source.exists():
self.stdout.write(
f"WARNING: Both {txt_source} and {html_source} exist."
)
if txt_source.exists() or html_source.exists():
prefix = DocTypeName.objects.get(slug=type_id).prefix
doc_name = f"{prefix}-interim-{dt.year}-iesg-{counter:02d}-{dt:%Y%m%d%H%M}"
doc_filename = f"{doc_name}-00.txt"
suffix = "html" if html_source.exists() else "txt"
doc_filename = f"{doc_name}-00.{suffix}"
verbose_type = (
"Minutes" if type_id == "minutes" else "Narrative Minutes"
)
Expand Down Expand Up @@ -300,6 +315,23 @@ def handle(self, *args, **options):
)
else:
os.makedirs(dest.parent, exist_ok=True)
shutil.copy(source, dest)
if html_source.exists():
html_content = html_source.read_text(encoding="utf-8")
html_content = html_content.replace(
f'href="IESGnarrative-{dt:%Y-%m-%d}.html#',
'href="#',
)
html_content = re.sub(
r'<a href="file:///[^"]*">([^<]*)</a>',
r"\1",
html_content,
)
html_content = html_content.replace(
'<p><a href="http://validator.w3.org/check?uri=referer"><img src="3" alt="Valid HTML 4.01 Strict" height="31" width="88" /></a> </p>',
"",
)
dest.write_text(html_content, encoding="utf-8")
else:
shutil.copy(txt_source, dest)

counter += 1

0 comments on commit 96398b6

Please sign in to comment.