Created
June 4, 2019 19:58
-
-
Save zackmdavis/b88a5eb8f1c17d2cd576343c00e221d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
import re | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
terms = ["application", "breach notice law", "breach response costs", "business interruption loss", "claim", "claim expenses", "computer systems", "continuity date", "crisis management costs", "cyber extortion", "cyber extortion expenses", "cyber terrorism", "damages", "data breach", "denial of service attack", "digital asset", "employee", "extra expenses", "funds transfer fraud", "funds transfer loss", "incident", "indemnity period", "you", "your", "loss", "malicious code", "media content", "merchant service agreement", "multimedia wrongful act", "named insured", "pci fines and assessments", "personally identifiable information", "policy period", "pollutants", "privacy liability", "privacy policy", "public relations event", "ransomware", "regulatory penalties", "regulatory proceeding", "restoration costs", "retroactive date", "security failure", "senior executive", "service provider", "subsidiary", "systems failure", "third party corporate information", "waiting period", "we", "us", "our"] | |
term_regex = re.compile(r"(?<!textbf{{)\b({})\b".format("|".join(term for term in terms)), re.IGNORECASE) | |
def replace_prompt(match): | |
original = match.group() | |
replacement = "\textbf{{{}}}".format(original) | |
excerpt = match.string[match.start()-20:match.start()] + "*" + original + "*" + match.string[match.end():match.end()+20] | |
goahead = input("Bold '{}' in '{}'? ".format(original, excerpt)) | |
if goahead[0].lower() == "y": | |
return replacement | |
else: | |
return original | |
def do_bolding(content): | |
terms_to_bold = term_regex.findall(content) | |
logging.info("found %s terms: %r", len(terms_to_bold), terms_to_bold) | |
revised = term_regex.sub(replace_prompt, content) | |
return revised | |
if __name__ == "__main__": | |
path = sys.argv[1] | |
with open(path) as f: | |
content = f.read() | |
do_bolding(content) | |
with open(path, 'w') as f: | |
f.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment