webexteamsarchiver_4.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. def _archive(self, reverse_order: bool, download_attachments: bool,
  2. download_avatars: bool, download_workers: int, text_format: bool,
  3. html_format: bool, json_format: bool, timestamp_format: str) -> None:
  4. """
  5. Collects room messages and attachments using Webex Teams
  6. APIs and writes them to text/html files.
  7. """
  8. if reverse_order:
  9. self.messages_with_threads = list(reversed(list(self.messages_with_threads)))
  10. else:
  11. self.messages_with_threads = list(self.messages_with_threads)
  12. if html_format:
  13. self._create_html_transcript(self.messages_with_threads, self.attachments, self.people,
  14. download_avatars, timestamp_format)
  15. logger.debug("HTML transcript completed.")
  16. if text_format:
  17. self._create_text_transcript(
  18. self.messages_with_threads, self.attachments, self.people, timestamp_format)
  19. logger.debug("Text transcript completed.")
  20. if json_format:
  21. self._create_json_transcript(self.messages)
  22. logger.debug("JSON transcript completed.")
  23. if download_attachments:
  24. self._download_files(
  25. "attachments", self.attachments, download_workers)
  26. logger.debug("Attachments download completed.")
  27. if download_avatars:
  28. self._download_files("avatars", self.avatars, download_workers)
  29. logger.debug("Avatars download completed.")
  30. # Write space information to json file
  31. with open(os.path.join(os.getcwd(), self.archive_folder_name, f"space_details.json"), "w", encoding="utf-8") as fh:
  32. space_details = {
  33. "space": self.room.to_dict(),
  34. "creator": self.room_creator._asdict() if isinstance(self.room_creator, UserNotFound)
  35. else self.room_creator.to_dict(),
  36. }
  37. json.dump(space_details, fh)
  38. logger.info("Room %s archived successfully.", self.room.id)