Dual format persistence fixes

This commit is contained in:
Piotr Dec 2025-04-30 13:39:31 +02:00
parent c36276aee5
commit 066232222f
No known key found for this signature in database
GPG key ID: D3B5A5D0150D147A

View file

@ -373,10 +373,11 @@ class SlackExporter:
self.export_user_list(True)
for channel_id in channels:
print(f"Eksport {channels_map.get(channel_id).label}...")
print(f"[{channel_id}] Historia")
self.export_channel_history(channel_id)
self.export_channel_history(channel_id, as_json=True)
print(f"[{channel_id}] Odpowiedzi")
self.export_channel_replies(channel_id)
self.export_channel_replies(channel_id, as_json=True)
print(f"[{channel_id}] Pliki")
self.export_channel_files(channel_id)
def export_channel_list(self, as_json: bool = False):
@ -396,10 +397,13 @@ class SlackExporter:
self._save_data(data, "user_list", as_json)
def export_channel_history(self, channel_id: str, oldest: Optional[str] = None,
latest: Optional[str] = None, as_json: bool = False):
"""Eksportuje historię kanału"""
latest: Optional[str] = None):
history = self.api.get_channel_history(channel_id, oldest, latest)
self._export_channel_history(channel_id, history, True)
self._export_channel_history(channel_id, history, False)
def _export_channel_history(self, channel_id: str, history: List[Dict], as_json: bool):
"""Eksportuje historię kanału"""
if as_json:
data = history
else:
@ -416,16 +420,18 @@ class SlackExporter:
self._save_data(data, f"channel_{channel_id}", as_json)
def export_channel_replies(self, channel_id: str, oldest: Optional[str] = None,
latest: Optional[str] = None, as_json: bool = False):
"""Eksportuje wątki w kanale"""
latest: Optional[str] = None):
history = self.api.get_channel_history(channel_id, oldest, latest)
thread_messages = [msg for msg in history if "reply_count" in msg]
all_replies = []
for msg in thread_messages:
replies = self.api.get_replies(channel_id, msg["ts"])
all_replies.extend(replies)
self._export_channel_replies(channel_id, all_replies, True)
self._export_channel_replies(channel_id, all_replies, False)
def _export_channel_replies(self, channel_id: str, all_replies: List[Dict], as_json: bool):
"""Eksportuje wątki w kanale"""
if as_json:
data = all_replies
else:
@ -459,6 +465,7 @@ class SlackExporter:
with open(target, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Zapisano plik {target}")
return True
except requests.exceptions.RequestException as e:
print(f"Error downloading file {filename}: {e}. {attempts} attempts left.")