check_images.py 726 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. import io
  3. import os
  4. import re
  5. #path = os.getcwd()
  6. #print path
  7. startpattern = """images/"""
  8. imgFormats = ['jpg','gif']
  9. infile = io.open('glife.txt',mode='r',encoding='utf-16')
  10. lines = infile.readlines()
  11. images = []
  12. for name in os.listdir("locations"):
  13. ifile = io.open(
  14. os.path.join("locations", name),
  15. mode='rt',
  16. encoding='utf-8'
  17. )
  18. text = ifile.read()
  19. for match in re.finditer(r"images.+?[.](gif|jpg|png)", text, flags=re.U):
  20. imgfile = match.group().encode("utf-8")
  21. images.append(imgfile)
  22. ifile.close()
  23. for image in images:
  24. if not re.search(r"[<$]", image) and not os.path.isfile(image):
  25. print "Image not found:", image