From 971eb4f99a1441bd3d4b14699fcdf78ccebc1c17 Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 12 Feb 2024 12:40:56 -0700 Subject: [PATCH] Adding many more Stack Exchange Zim subscriptions. --- modules/zim/kiwix.py | 40 ++++++++++++++++++++++++++++++++++++ modules/zim/lib.py | 30 +++++++++++++++++++++++++++ modules/zim/test/test_lib.py | 18 +++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/modules/zim/kiwix.py b/modules/zim/kiwix.py index 4a9cda5c..d2bf9901 100644 --- a/modules/zim/kiwix.py +++ b/modules/zim/kiwix.py @@ -134,6 +134,46 @@ KIWIX_CATALOG = [ 'languages': ['en'], 'size': 62 * 1048576, }, + { + 'name': 'DIY (Stack Exchange)', + 'languages': ['en'], + 'size': 930 * 1048576, + }, + { + 'name': 'Electronics (Stack Exchange)', + 'languages': ['en'], + 'size': 1.4 * 1073741824, + }, + { + 'name': 'Unix (Stack Exchange)', + 'languages': ['en'], + 'size': 1.1 * 1073741824, + }, + { + 'name': 'Ask Ubuntu (Stack Exchange)', + 'languages': ['en'], + 'size': 1.9 * 1073741824, + }, + { + 'name': 'Bicycles (Stack Exchange)', + 'languages': ['en'], + 'size': 350 * 1048576, + }, + { + 'name': 'Biology (Stack Exchange)', + 'languages': ['en'], + 'size': 350 * 1048576, + }, + { + 'name': 'Arduino (Stack Exchange)', + 'languages': ['en'], + 'size': 240 * 1048576, + }, + { + 'name': '3D Printing (Stack Exchange)', + 'languages': ['en'], + 'size': 100 * 1048576, + }, ] KIWIX_CATALOG_BY_NAME = {i['name']: i for i in KIWIX_CATALOG} diff --git a/modules/zim/lib.py b/modules/zim/lib.py index 722d1962..380d7433 100644 --- a/modules/zim/lib.py +++ b/modules/zim/lib.py @@ -323,6 +323,20 @@ async def subscribe(name: str, language: str, session: Session = None, url = f'https://download.kiwix.org/zim/gutenberg/gutenberg_{language}_all_' elif name == 'Amateur Radio (Stack Exchange)': url = f'https://download.kiwix.org/zim/stack_exchange/ham.stackexchange.com_{language}_all_' + elif name == 'DIY (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/diy.stackexchange.com_{language}_all_' + elif name == 'Electronics (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/electronics.stackexchange.com_{language}_all' + elif name == 'Unix (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/unix.stackexchange.com_{language}_all' + elif name == 'Ask Ubuntu (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/askubuntu.com_{language}_all_' + elif name == 'Bicycles (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/bicycles.stackexchange.com_{language}_all_' + elif name == 'Biology (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/biology.stackexchange.com_{language}_all_' + elif name == '3D Printing (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/3dprinting.stackexchange.com_{language}_all_' else: raise ValueError(f'{name} not a valid Kiwix subscription name!') @@ -387,6 +401,22 @@ def zim_download_url_to_name(url: str) -> Tuple[str, str]: name = 'Gutenberg' elif project == 'ham.stackexchange.com' and flavor == '_all_': name = 'Amateur Radio (Stack Exchange)' + elif project == 'diy.stackexchange.com' and flavor == '_all_': + name = 'DIY (Stack Exchange)' + elif project == 'electronics.stackexchange.com' and flavor == '_all_': + name = 'Electronics (Stack Exchange)' + elif project == 'unix.stackexchange.com' and flavor == '_all_': + name = 'Unix (Stack Exchange)' + elif project == 'askubuntu.com' and flavor == '_all_': + name = 'Ask Ubuntu (Stack Exchange)' + elif project == 'bicycles.stackexchange.com' and flavor == '_all_': + name = 'Bicycles (Stack Exchange)' + elif project == 'biology.stackexchange.com' and flavor == '_all_': + name = 'Biology (Stack Exchange)' + elif project == 'arduino.stackexchange.com' and flavor == '_all_': + name = 'Arduino (Stack Exchange)' + elif project == '3dprinting.stackexchange.com' and flavor == '_all_': + name = '3D Printing (Stack Exchange)' else: raise RuntimeError(f'Could not find name for Zim URL: {url} {project=} {flavor=}') diff --git a/modules/zim/test/test_lib.py b/modules/zim/test/test_lib.py index 4bb7d9f0..159b47cb 100644 --- a/modules/zim/test/test_lib.py +++ b/modules/zim/test/test_lib.py @@ -264,7 +264,23 @@ def test_zim_tag_migration(test_session, test_directory, zim_factory, tag_factor ('https://download.kiwix.org/zim/ifixit/ifixit_nl_all_', ('iFixit', 'nl')), ('https://download.kiwix.org/zim/gutenberg/gutenberg_ang_all_', ('Gutenberg', 'ang')), ('https://download.kiwix.org/zim/stack_exchange/ham.stackexchange.com_en_all_', - ('Amateur Radio (Stack Exchange)', 'en')) + ('Amateur Radio (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/diy.stackexchange.com_en_all_', + ('DIY (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/electronics.stackexchange.com_en_all_', + ('Electronics (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/unix.stackexchange.com_en_all_', + ('Unix (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/askubuntu.com_en_all_', + ('Ask Ubuntu (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/bicycles.stackexchange.com_en_all_', + ('Bicycles (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/biology.stackexchange.com_en_all_', + ('Biology (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/arduino.stackexchange.com_en_all_', + ('Arduino (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/3dprinting.stackexchange.com_en_all_', + ('3D Printing (Stack Exchange)', 'en')), ] ) def test_zim_download_url_to_name(url, expected):