webexteamsarchiver_3.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. def archive_room(self, room_id: str, text_format: bool = True, html_format: bool = True,
  2. json_format: bool = True, **options) -> str:
  3. """
  4. Archives a Webex Teams room. This creates a file called roomTitle_timestamp_roomId with the
  5. appropriate file extension as defined by file_format param with the following contents:
  6. - roomTitle_roomId.txt - Text version of the conversations (if `text_format` is True)
  7. - roomTitle_roomId.html - HTML version of the conversations (if `html_format` is True)
  8. - files/ - Attachments added to the room (if `download_attachments` is True)
  9. Args:
  10. room_id: ID of the room to archive.
  11. text_format: Create a text version of the archive.
  12. html_format: Create an HTML version of the archive.
  13. json_format: Create a json version of the archive.
  14. Options:
  15. compress_folder: Compress archive folder.
  16. delete_folder: Delete the archive folder when done.
  17. reverse_order: Order messages by most recent on the bottom.
  18. download_attachments: Download attachments sent to the room.
  19. download_avatars: Download avatar images.
  20. download_workers: Number of download workers for downloading files.
  21. timestamp_format: Timestamp strftime format.
  22. file_format: Archive format as supported by shutil.make_archive
  23. Returns:
  24. Name of archive file.
  25. Raises:
  26. IOError: Error occurred while creating/writing to files.
  27. shutil.Error: Error occurred creating/copying/deleting files/folders.
  28. ValueError: Exception message will contain more details.
  29. TypeError: Messages contained non JSON serializable data.
  30. webexteamssdkException: An error occurred calling the Webex Teams API.
  31. """
  32. # Configure options
  33. compress_folder = options.get("compress_folder", True)
  34. delete_folder = options.get("delete_folder", False)
  35. reverse_order = options.get("reverse_order", True)
  36. download_attachments = options.get("download_attachments", True)
  37. download_avatars = options.get("download_avatars", True)
  38. download_workers = options.get("download_workers", 15)
  39. timestamp_format = options.get("timestamp_format", "%Y-%m-%dT%H:%M:%S")
  40. file_format = options.get("file_format", "gztar")
  41. if delete_folder and not compress_folder:
  42. raise ValueError("delete_folder cannot be True while compress_folder is False")
  43. self._gather_room_information(room_id, download_avatars)
  44. # Prepare folder
  45. self._setup_folder(download_attachments, download_avatars, html_format)
  46. try:
  47. self._archive(reverse_order, download_attachments, download_avatars, download_workers,
  48. text_format, html_format, json_format, timestamp_format)
  49. if compress_folder:
  50. filename = self._compress_folder(file_format)
  51. else:
  52. filename = self.archive_folder_name
  53. except Exception:
  54. self._tear_down_folder()
  55. raise
  56. if delete_folder:
  57. self._tear_down_folder()
  58. return filename