check_images2.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. infile = io.open('glife.txt',mode='r',encoding='utf-16')
  11. lines = infile.readlines()
  12. images = []
  13. for name in os.listdir("locations"):
  14. path = os.path.join("locations", name)
  15. if os.path.isdir(path):
  16. continue
  17. # skip directories
  18. else:
  19. ifile = io.open(
  20. os.path.join("locations", name),
  21. mode='rt',
  22. encoding='utf-8'
  23. )
  24. text = ifile.read()
  25. for match in re.finditer(r"images.+?[.](gif|jpg|png|mp4)", text, flags=re.U):
  26. imgfile = match.group().encode("utf-8")
  27. randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
  28. if randmatch != None:
  29. for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
  30. images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
  31. else:
  32. images.append(imgfile)
  33. ifile.close()
  34. for image in images:
  35. if not re.search(r"[<$]", image) and not os.path.isfile(image):
  36. print "Image not found:", image