Created
June 17, 2020 14:38
-
-
Save iainlane/2607b426837fe885a1760e9639871a9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from collections import defaultdict | |
import lzma | |
import os | |
import pprint | |
import yaml | |
NEW = "update_excuses_new.yaml.xz" | |
OLD = "update_excuses_old.yaml" | |
excuses = defaultdict(dict) | |
nf = lzma.open(NEW, "rt", encoding="utf-8") | |
ny = yaml.load(nf.read(), Loader=yaml.CSafeLoader)["sources"] | |
nf.close() | |
of = open(OLD, "rt", encoding="utf-8") | |
oy = yaml.load(of.read(), Loader=yaml.CSafeLoader)["sources"] | |
of.close() | |
for item in ny: | |
name = item["item-name"] | |
del item["excuses"] | |
excuses[name]["new"] = item | |
for item in oy: | |
name = item["item-name"] | |
excuses[name]["old"] = item | |
different_excuses = ( | |
excuses[k] | |
for k in excuses | |
if ("old" not in excuses[k] or "new" not in excuses[k]) | |
or excuses[k]["old"]["is-candidate"] != excuses[k]["new"]["is-candidate"] | |
) | |
print( | |
""" | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>update_excuses.yaml diffs</title> | |
<body> | |
<table style="width: 100%; table-layout: fixed"> | |
<tr><th>old</th><th>new</th></tr> | |
""" | |
) | |
pp = pprint.PrettyPrinter(indent=4) | |
for e in different_excuses: | |
print("<tr>") | |
try: | |
name = e["old"]["item-name"] | |
except KeyError: | |
name = e["new"]["item-name"] | |
print("<th colspan='2'>{}".format(name)) | |
print("</tr>") | |
try: | |
print( | |
"<td style='width: 50%'><pre style='white-space: pre-wrap'>{}</pre></td>".format(pp.pformat(e['old'])) | |
) | |
except KeyError: | |
print("<td>(not in the old output)</td>") | |
try: | |
print( | |
"<td style='width: 50%'><pre style='white-space: pre-wrap'>{}</pre></td>".format(pp.pformat(e['new'])) | |
) | |
except KeyError: | |
print("<td>(not in the new output)</td>") | |
print( | |
""" | |
</body> | |
</html> | |
""" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment