Last active
June 21, 2021 13:55
-
-
Save peterbe/8e64574dcfea77b73f60d0c5da9e07b2 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
from pathlib import Path | |
fixes = [] | |
class Stop(Exception): | |
"""exit early""" | |
NEEDLES = [""" | |
<p class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> | |
""", | |
""" | |
<div class="hidden">La table de compatibilidad en esta página se genera a partir de los datos estructurados. Si le gustaría contrubuir con los datos, por favor revise <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíenos un un pull request.</div> | |
""", | |
""" | |
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> | |
""", | |
""" | |
<div class="hidden">La tabla de compatibilidad en esta página se genera a partir de datos estructurados. Si desea contribuir con los datos, por favor visite <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíanos una petición de actualización.</div> | |
""", | |
""" | |
<p class="hidden"><span class="seoSummary">La compatibilidad de la tabla en esta pagina es generada por la estructura de datos. Si tú gustas contribuir, por favor dirigete a <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envia un pull Request</span></p> | |
""", | |
""" | |
<div class="hidden">La tabla de compatibilidad en esta página se genera a partir de datos estructurados. Si desea contribuir con los datos, consulte https://github.com/mdn/browser-compat-data y envíenos una solicitud de extracción.</div> | |
""", | |
""" | |
<div class="hidden">La tabla de compatibilidad en esta página está generada desde datos estructurados. Si quieres contribuir a los datos, por favor visita <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíanos una pull request.</div> | |
""", | |
""" | |
<div class="hidden">La tabla de compatibilidad en esta página se genera a partir de datos estructurados. Si desea contribuir a los datos, consulte <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíanos un pull request.</div> | |
""", | |
""" | |
<div class="hidden">La tabla de compatibilidad en esta pagina es generada de datos estructurados. Si te gustaría contribuir a los datos, por favor haz check out de <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envianos una petición pull.</div> | |
""", | |
""" | |
<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div> | |
""", | |
""" | |
<div class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div> | |
""", | |
'<p class="hidden">To contribute to this compatibility data, please write a pull request against this file: <a href="https://github.com/mdn/browser-compat-data/blob/master/javascript/promise.json">https://github.com/mdn/browser-compat-data/blob/master/javascript/promise.json</a>.</p>' | |
] | |
NEEDLES = list(set(NEEDLES)) | |
def fix(path): | |
if len(fixes) > 35: | |
raise Stop | |
new_content = "" | |
with open(path) as f: | |
content = f.read() | |
for needle in NEEDLES: | |
if needle in content: | |
new_content = content.replace(needle, "") | |
elif needle.replace('\xa0', ' ') in content: | |
new_content = content.replace(needle.replace('\xa0', ' '), "") | |
elif needle.strip() in content: | |
raise Exception(path) | |
if not new_content: | |
for line in content.splitlines(): | |
if 'class="hidden"' in line and 'https://github.com/mdn/browser-compat-data' in line: | |
print("WHAT ABOUT?", path) | |
print(repr(line)) | |
if input("Add? [Y/n] ").lower() != 'n': | |
NEEDLES.append(f"\n{line}\n") | |
NEEDLES.append(line) | |
return fix(path) | |
if new_content: | |
print("CHANGE", path) | |
with open(path, "w") as f: | |
f.write(new_content) | |
fixes.append(path) | |
def walk(root: Path): | |
for thing in root.iterdir(): | |
if thing.is_dir(): | |
walk(thing) | |
elif thing.name == "index.html": | |
if 'conflicting' in str(thing): | |
print("SKIP", thing) | |
continue | |
fix(thing) | |
try: | |
walk(Path("files/es")) | |
except Stop: | |
print("MAX REACHED!") | |
print(len(fixes)) | |
from pprint import pprint | |
pprint(list(set(NEEDLES))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment