check_images.py 1.1 KB

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