Skip to content

Commit 4128b31

Browse files
Merge pull request #74 from Dineshkarthik/73-update-failed_ids-per-batch
Update `ids_to_retry` for every batch of processed messages
2 parents 6b6bab7 + 13d4e3d commit 4128b31

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

media_downloader.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def update_config(config: dict):
3131
config: dict
3232
Configuraiton to be written into config file.
3333
"""
34+
config["ids_to_retry"] = list(set(config["ids_to_retry"] + FAILED_IDS))
3435
with open("config.yaml", "w") as yaml_file:
3536
yaml.dump(config, yaml_file, default_flow_style=False)
3637
logger.info("Updated last read message_id to config file")
@@ -345,14 +346,11 @@ def main():
345346
updated_config = asyncio.get_event_loop().run_until_complete(
346347
begin_import(config, pagination_limit=100)
347348
)
348-
updated_config["ids_to_retry"] = list(
349-
set(updated_config["ids_to_retry"] + FAILED_IDS)
350-
)
351349
if FAILED_IDS:
352350
logger.info(
353351
"Downloading of %d files failed. "
354-
"Failed message ids are to config file.\n"
355-
"Functionality to download failed downloads will be added "
352+
"Failed message ids are added to config file.\n"
353+
"Functionality to re-download failed downloads will be added "
356354
"in the next version of `Telegram-media-downloader`",
357355
len(set(FAILED_IDS)),
358356
)

tests/test_media_downloader.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"api_hash": "hasw5Tgawsuj67",
3030
"last_read_message_id": 0,
3131
"chat_id": 8654123,
32+
"ids_to_retry": [],
3233
"media_types": ["audio", "voice"],
3334
"file_formats": {"audio": ["all"], "voice": ["all"]},
3435
}
@@ -100,7 +101,7 @@ def __init__(self):
100101
pass
101102

102103
def run_until_complete(self, *args, **kwargs):
103-
return {"api_id": 1, "api_hash": "asdf", "ids_to_retry": [1]}
104+
return {"api_id": 1, "api_hash": "asdf", "ids_to_retry": [1, 2, 3]}
104105

105106

106107
class MockAsync:
@@ -474,16 +475,21 @@ def test_download_media(self, mock_logger, patched_time_sleep):
474475
@mock.patch("__main__.__builtins__.open", new_callable=mock.mock_open)
475476
@mock.patch("media_downloader.yaml", autospec=True)
476477
def test_update_config(self, mock_yaml, mock_open):
477-
conf = {"api_id": 123, "api_hash": "hasw5Tgawsuj67"}
478+
conf = {
479+
"api_id": 123,
480+
"api_hash": "hasw5Tgawsuj67",
481+
"ids_to_retry": [],
482+
}
478483
update_config(conf)
479484
mock_open.assert_called_with("config.yaml", "w")
480485
mock_yaml.dump.assert_called_with(
481486
conf, mock.ANY, default_flow_style=False
482487
)
483488

489+
@mock.patch("media_downloader.update_config")
484490
@mock.patch("media_downloader.pyrogram.Client", new=MockClient)
485491
@mock.patch("media_downloader.process_messages", new=mock_process_message)
486-
def test_begin_import(self):
492+
def test_begin_import(self, mock_update_config):
487493
result = self.loop.run_until_complete(async_begin_import(MOCK_CONF, 3))
488494
conf = copy.deepcopy(MOCK_CONF)
489495
conf["last_read_message_id"] = 5

utils/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Init namespace"""
22

3-
__version__ = "0.3.0"
3+
__version__ = "0.3.1"
44
__license__ = "MIT License"
55
__copyright__ = (
66
"Copyright (C) 2019 Dineshkarthik <https://github.com/Dineshkarthik>"

0 commit comments

Comments
 (0)