joplinRemoveCheckedItems.py 864 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/python2.7
  2. import sys
  3. import os
  4. def remove_checked_items(file_path):
  5. try:
  6. with open(file_path, 'r') as file:
  7. lines = file.readlines()
  8. with open(file_path, 'w') as file:
  9. for line in lines:
  10. if not line.startswith("- [x]"):
  11. file.write(line)
  12. except FileNotFoundError:
  13. sys.stderr.write("File not found: {}".format(file_path))
  14. except Exception as e:
  15. sys.stderr.write("An error occurred: {}".format(str(e)))
  16. if __name__ == "__main__":
  17. if len(sys.argv) != 2:
  18. print("Usage: python remove_checked_items.py <file_path>")
  19. else:
  20. #if os.environ.get('REMOVE_CHECKED') is not None:
  21. file_path = sys.argv[1]
  22. remove_checked_items(file_path)
  23. #else:
  24. # print("No environment variable set to define behavior")