A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

37 lines
870 B

  1. #!/usr/bin/env python
  2. """Locate any orphaned photos.
  3. Usage: scripts/orphaned-photos.py <path/to/db> <path/to/static/photos>"""
  4. import sys
  5. import os
  6. import codecs
  7. import json
  8. import glob
  9. sys.path.append(".")
  10. import rophako.jsondb as JsonDB
  11. def main():
  12. if len(sys.argv) == 1:
  13. print "Usage: {} <path/to/static/photos>".format(__file__)
  14. sys.exit(1)
  15. photo_root = sys.argv[1]
  16. db = JsonDB.get("photos/index")
  17. photos = set()
  18. for album in db["albums"]:
  19. for key, data in db["albums"][album].iteritems():
  20. for img in ["large", "thumb", "avatar"]:
  21. photos.add(data[img])
  22. # Get all the images and compare.
  23. for img in glob.glob("{}/*.*".format(photo_root)):
  24. fname = img.split("/")[-1]
  25. if not fname in photos:
  26. print "Orphan:", fname
  27. if __name__ == "__main__":
  28. main()