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.

orphaned-photos.py 911B

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