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 1006B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals, print_function, absolute_import
  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. from rophako.settings import Config
  12. Config.load_settings()
  13. import rophako.jsondb as JsonDB
  14. def main():
  15. if len(sys.argv) == 1:
  16. print("Usage: {} <path/to/static/photos>".format(__file__))
  17. sys.exit(1)
  18. photo_root = sys.argv[1]
  19. db = JsonDB.get("photos/index")
  20. photos = set()
  21. for album in db["albums"]:
  22. for key, data in db["albums"][album].iteritems():
  23. for img in ["large", "thumb", "avatar"]:
  24. photos.add(data[img])
  25. # Get all the images and compare.
  26. for img in glob.glob("{}/*.*".format(photo_root)):
  27. fname = img.split("/")[-1]
  28. if not fname in photos:
  29. print("Orphan:", fname)
  30. if __name__ == "__main__":
  31. main()