Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from docx import Document
- from docx.enum.text import WD_COLOR_INDEX
- import os
- keywords= ["Scripting", "Shell", "Ansible", "ansible", "Bash", "Jenkins", "Jboss", "jboss", "Apache", "apache", "Tomcat", "tomcat", "shell", "Python", "python", "Ruby", "ruby", "puppet", "Puppet", "satellite", "Satellite"]
- def highlight_filename(filename):
- doc = Document(filename)
- for paragraph in doc.paragraphs:
- for key in keywords:
- if key in paragraph.text:
- inline = paragraph.runs
- for run in paragraph.runs:
- if key in run.text:
- x = run.text.split(key)
- run.clear()
- for i in range(len(x) - 1):
- run.add_text(x[i])
- run.add_text(key)
- run.font.highlight_color = WD_COLOR_INDEX.YELLOW
- doc.save('%s-edit.docx' % filename)
- return 1
- if __name__ == '__main__':
- path = '.'
- files = os.listdir(path)
- for file in files:
- if file.endswith("docx"):
- highlight_filename(file)
Add Comment
Please, Sign In to add comment