1
0

check_images.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
  22. if randmatch != None:
  23. for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
  24. images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
  25. else:
  26. images.append(imgfile)
  27. ifile.close()
  28. for image in images:
  29. if not re.search(r"[<$]", image) and not os.path.isfile(image):
  30. print "Image not found:", image