examplescript.py 863 B

123456789101112131415161718192021222324252627282930
  1. #
  2. # This is an example script that can be used as
  3. # pwman -p examplescript.py
  4. # pwman --call-pymod examplescript.py
  5. #
  6. # See pwman --help for more information about the command line options.
  7. # See doc/api/ for a description of the Python API.
  8. #
  9. # Entry point.
  10. # The 'db' parameter is a PWManDatabase instance.
  11. # See doc/api/libpwman/database.html
  12. def run(db):
  13. # Print all category names.
  14. categories = db.getCategoryNames()
  15. print("Categories:", categories)
  16. # Print all titles in a category.
  17. titles = db.getEntryTitles("testcat1")
  18. print("Titles in testcat1:", titles)
  19. # Move all titles from a category to another one and change the title.
  20. for title in titles:
  21. entry = db.getEntry("testcat1", title)
  22. print("Moving entry:", entry)
  23. db.moveEntry(entry, "othercat", "foobar_" + title)
  24. # Permanently write the changes to the database file.
  25. db.commit()