Guest User

Untitled

a guest
Jan 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. from docx import Document
  2. from docx.enum.text import WD_COLOR_INDEX
  3. import os
  4.  
  5.  
  6. keywords= ["Scripting", "Shell", "Ansible", "ansible", "Bash", "Jenkins", "Jboss", "jboss", "Apache", "apache", "Tomcat", "tomcat", "shell", "Python", "python", "Ruby", "ruby", "puppet", "Puppet", "satellite", "Satellite"]
  7.  
  8.  
  9. def highlight_filename(filename):
  10.  
  11. doc = Document(filename)
  12. for paragraph in doc.paragraphs:
  13. for key in keywords:
  14. if key in paragraph.text:
  15. inline = paragraph.runs
  16. for run in paragraph.runs:
  17. if key in run.text:
  18. x = run.text.split(key)
  19. run.clear()
  20. for i in range(len(x) - 1):
  21. run.add_text(x[i])
  22. run.add_text(key)
  23. run.font.highlight_color = WD_COLOR_INDEX.YELLOW
  24.  
  25.  
  26. doc.save('%s-edit.docx' % filename)
  27. return 1
  28.  
  29.  
  30. if __name__ == '__main__':
  31. path = '.'
  32. files = os.listdir(path)
  33. for file in files:
  34. if file.endswith("docx"):
  35. highlight_filename(file)
Add Comment
Please, Sign In to add comment