remove-music-dirs-with-just-image 949 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. from pathlib import PureWindowsPath
  5. path = sys.argv[1]
  6. def getImportDate(line):
  7. date = line.lstrip('<Field Name="Date Imported">')
  8. date = date.rstrip('</Field>\n')
  9. return int(date)
  10. def getCreateDate(line):
  11. date = line.lstrip('<Field Name="Date Created">')
  12. date = date.rstrip('</Field>\n')
  13. return int(date)
  14. f = open(in_file, "r")
  15. lines = f.readlines()
  16. f.close()
  17. for lnum,line in enumerate(lines):
  18. if '<Field Name="Date Imported">' in line:
  19. import_date = getImportDate(line)
  20. date_imported_line = lnum
  21. elif '<Field Name="Date Created">' in line:
  22. create_date = getCreateDate(line)
  23. if create_date < import_date:
  24. print(import_date, create_date)
  25. lines[date_imported_line] = f'<Field Name="Date Imported">{create_date}</Field>\n'
  26. f = open(out_file, 'w')
  27. f_string = "".join(lines)
  28. f.write(f_string)
  29. f.close()
  30. exit()