1
1

check_images2.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. import io
  3. import os
  4. import re
  5. import sys
  6. #path = os.getcwd()
  7. #print path
  8. startpattern = """images/"""
  9. imgFormats = ['jpg','gif','png','mp4']
  10. images = []
  11. for name in os.listdir("locations"):
  12. path = os.path.join("locations", name)
  13. if os.path.isdir(path):
  14. continue
  15. # skip directories
  16. else:
  17. ifile = io.open(
  18. os.path.join("locations", name),
  19. mode='rt',
  20. encoding='utf-8'
  21. )
  22. text = ifile.read()
  23. for match in re.finditer(r"images.+?[.](gif|jpg|png|mp4)", text, flags=re.U):
  24. imgfile = match.group().encode("utf-8")
  25. randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
  26. if randmatch != None:
  27. for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
  28. images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
  29. else:
  30. images.append(imgfile)
  31. ifile.close()
  32. for image in images:
  33. if not re.search(r"[<$]", image) and not os.path.isfile(image):
  34. print "Image not found:", image