check_images3.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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")
  28. imgfile = imgfile.decode('utf-8')
  29. randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
  30. if randmatch != None:
  31. for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
  32. images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
  33. else:
  34. images.append(imgfile)
  35. ifile.close()
  36. for image in images:
  37. if not re.search(r"[<$]", image) and not os.path.isfile(image):
  38. print ("Image not found:", image)