Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

helpers.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import csv
  2. import os
  3. import sys
  4. import zipfile
  5. from datetime import datetime
  6. def get_humane_date(timestamp, date_format):
  7. return datetime.fromtimestamp(timestamp).strftime(date_format)
  8. def write_csv(csv_path, FIELD_NAMES, rows):
  9. with open(csv_path, "w", encoding="UTF8", newline="") as file:
  10. writer = csv.DictWriter(file, fieldnames=FIELD_NAMES)
  11. writer.writeheader()
  12. writer.writerows(rows)
  13. def package_zip(zip_path, absolute_starting_path, zip_root_path, csv_path):
  14. shutil.make_archive(
  15. zip_path.replace(".zip", ""),
  16. "zip",
  17. absolute_starting_path.replace(zip_root_path, ""),
  18. zip_root_path,
  19. )
  20. zip = zipfile.ZipFile(zip_path, "a")
  21. zip.write(csv_path, os.path.basename(csv_path))
  22. zip.close()
  23. def create_export_directory(CONFIG):
  24. if os.path.exists(CONFIG["export_directory"]) and os.path.isdir(
  25. CONFIG["export_directory"]
  26. ):
  27. os.system("rm '%s' -r" % (CONFIG["export_directory"]))
  28. os.makedirs(CONFIG["export_directory"])
  29. def is_import_directory_okay(path):
  30. if not os.path.exists(path):
  31. raise ValueError("aborting: import directory path does not exist")
  32. if not os.path.isdir(path):
  33. raise ValueError("aborting: import directory path is not a directory")
  34. return True
  35. def get_document_space(CONFIG, current_path):
  36. relative_path = os.path.relpath(current_path, CONFIG["absolute_starting_path"])
  37. if relative_path == ".":
  38. document_space = CONFIG["document_space"]
  39. else:
  40. path = relative_path.replace(".", "_").replace("/", ".")
  41. document_space = f"{CONFIG['document_space']}.{path}"
  42. return document_space
  43. def get_attachments_folder_path(CONFIG, current_path):
  44. relative_path = os.path.relpath(current_path, CONFIG["absolute_starting_path"])
  45. if relative_path == ".":
  46. attachements_folder_path = os.path.basename(CONFIG["absolute_starting_path"])
  47. else:
  48. attachements_folder_path = relative_path.replace("/", ".")
  49. return attachements_folder_path
  50. def get_document_space_title(CONFIG, current_path):
  51. relative_path = os.path.relpath(current_path, CONFIG["absolute_starting_path"])
  52. if relative_path == ".":
  53. document_space_title = CONFIG["document_space_title"]
  54. else:
  55. document_space_title = os.path.basename(current_path)
  56. return document_space_title