1
1

check_images2.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. jmages = []
  12. filename_false = 'LinksToSkip.txt'
  13. with io.open(filename_false, 'r', encoding='UTF-8') as file:
  14. linesfalse = file.readlines()
  15. linesfalse = [line.rstrip() for line in linesfalse]
  16. file.close()
  17. ifile = io.open(
  18. "glife.txt",
  19. mode='rt',
  20. encoding='utf-16'
  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. ex = 0
  34. for jmage in jmages:
  35. if image == jmage:
  36. ex = 1
  37. break
  38. if ex == 0:
  39. ex = 0
  40. for line in linesfalse:
  41. if image == line:
  42. ex = 1
  43. break
  44. if ex == 0:
  45. jmages.append(image)
  46. for image in jmages:
  47. if not re.search(r"[<$]", image) and not os.path.isfile(image):
  48. print "Image not found:", image