Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Add convert script
Browse files Browse the repository at this point in the history
  • Loading branch information
lassik committed Mar 12, 2019
1 parent b53c156 commit d8e5e50
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env python3

import glob
import os
import re

GLOB = os.path.join(os.path.dirname(__file__), "srfi-*.html")


def naturalkey(htmlfile):
m = re.search(r"(\d+)\.html$", htmlfile)
return None if not m else int(m.group(1))


def convertdate(match):
y, m, d = [int(match.group(i)) for i in (2, 3, 4)]
olddate = match.group(1)
newdate = "{:d}-{:02d}-{:02d}".format(y, m, d)
dash_after_date = match.group(5)
if dash_after_date:
# Put spaces around the dash
newdate = newdate + " - "
print(olddate.ljust(10), " ", newdate, " ")
return newdate


for htmlfile in sorted(glob.glob(GLOB), key=naturalkey):
print()
print(os.path.basename(htmlfile))
OLDDATE = r"(((?:19|20)\d{2})/(\d{1,2})/(\d{1,2}))(-?)"
oldcontents = open(htmlfile, "r", newline="").read()
newcontents = re.sub(OLDDATE, convertdate, oldcontents)
open(htmlfile, "w", newline="").write(newcontents)

0 comments on commit d8e5e50

Please sign in to comment.