check_images3.py 1.3 KB

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