Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.

Export specific type(user, group, channel) #79

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Whitelist = @example, username, -1001132836449
; MediaWhitelist = chatphoto, photo, sticker
MediaWhitelist = chatphoto, photo, sticker

# dialog type to download. Options are:
# "user", "group", "channel".
# An empty list (default if omitted) means all are allowed.
DialogWhitelist = user, group, channel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps DialogFilter fits better since we're filtering the type of the dialogs.


# The maximum allowed file size for a document before skipping it.
# For instance, "800KB" will only download files smaller or equal to 800KB.
# Allowed units are "B", "KB", "MB" and "GB" (decimal point allowed).
Expand Down
1 change: 1 addition & 0 deletions telegram_export/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def load_config(filename):
'SessionName': 'exporter',
'OutputDirectory': '.',
'MediaWhitelist': 'chatphoto, photo, sticker',
'DialogWhitelist': 'user, group, channel',
'MaxSize': '1MB',
'LogLevel': 'INFO',
'DBFileName': 'export',
Expand Down
14 changes: 13 additions & 1 deletion telegram_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,20 @@ async def start(self):
await self.downloader.start(entity)
else:
# Neither blacklist nor whitelist - get all
dialog_to_dump = (self.dumper.config.get('DialogWhitelist') or '').replace(' ' ,'').split(',')
for dialog in await self.client.get_dialogs(limit=None):
await self.downloader.start(dialog.entity)
if dialog.is_user:
dialogType = 'user'
elif dialog.is_group:
dialogType = 'group'
elif dialog.is_channel:
dialogType = 'channel'
else:
dialogType = 'unknown!'
Copy link
Collaborator

@Lonami Lonami Aug 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally not good. Also it's impossible that this happens.

if dialogType in dialog_to_dump:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String comparison? It's better if you have something like user_enabled, and check if dialog.user and dialog.user_enabled, or something.

await self.downloader.start(dialog.entity)
else:
continue

async def download_past_media(self):
"""
Expand Down