From afecb621149cadf43d8259613c3cb22c138a5705 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 13 Feb 2024 14:07:34 -0700 Subject: [PATCH] Adding medical wiki projects. --- modules/zim/kiwix.py | 31 +++++++++++++++++++++++++++++++ modules/zim/lib.py | 34 ++++++++++++++++++++++++++++++++-- modules/zim/test/test_lib.py | 12 ++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/modules/zim/kiwix.py b/modules/zim/kiwix.py index d2bf9901..f2dd8ba8 100644 --- a/modules/zim/kiwix.py +++ b/modules/zim/kiwix.py @@ -174,6 +174,37 @@ KIWIX_CATALOG = [ 'languages': ['en'], 'size': 100 * 1048576, }, + { + 'name': 'MD Wiki (Wiki Project Med Foundation)', + 'languages': ['en'], + 'size': 5.9 * 1073741824, + }, + { + 'name': 'WikiMed Medical Encyclopedia', + 'languages': ['ar', 'as', 'bn', 'bpy', 'de', 'en', 'es', 'fa', 'fr', 'gu', 'hi', 'it', 'ja', 'kn', 'lo', 'ml', + 'mr', 'or', 'pa', 'pt', 'ru', 'ta', 'te', 'uk', 'ur', 'zh'], + 'size': 6.3 * 1073741824, + }, + { + 'name': 'Post Disaster Resource Library', + 'languages': ['en'], + 'size': 763 * 1048576, + }, + { + 'name': 'Military Medicine', + 'languages': ['en'], + 'size': 82 * 1048576, + }, + { + 'name': 'WikEm (Global Emergency Medicine Wiki)', + 'languages': ['en'], + 'size': 42 * 1048576, + }, + { + 'name': 'Health (Stack Exchange)', + 'languages': ['en'], + 'size': 57 * 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 c495489c..c1f1950f 100644 --- a/modules/zim/lib.py +++ b/modules/zim/lib.py @@ -340,6 +340,18 @@ async def subscribe(name: str, language: str, session: Session = None, 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_' + elif name == 'MD Wiki (Wiki Project Med Foundation)': + url = f'https://download.kiwix.org/zim/other/mdwiki_{language}_all_' + elif name == 'WikiMed Medical Encyclopedia': + url = f'https://download.kiwix.org/zim/wikipedia/wikipedia_{language}_medicine_' + elif name == 'Post Disaster Resource Library': + url = f'https://download.kiwix.org/zim/other/zimgit-post-disaster_{language}_' + elif name == 'Military Medicine': + url = f'https://download.kiwix.org/zim/zimit/fas-military-medicine_{language}_' + elif name == 'WikEm (Global Emergency Medicine Wiki)': + url = f'https://download.kiwix.org/zim/other/wikem_{language}_all_maxi_' + elif name == 'Health (Stack Exchange)': + url = f'https://download.kiwix.org/zim/stack_exchange/health.stackexchange.com_{language}_all_' else: raise ValueError(f'{name} not a valid Kiwix subscription name!') @@ -365,11 +377,17 @@ async def unsubscribe(subscription_id: int, session: Session = None): raise UnknownZimSubscription(f'{subscription_id=}') -KIWIX_URL_PARSER = re.compile(r'https:\/\/download\.kiwix\.org\/zim\/(.+?)\/(.+?)_(\w{2,3})(_.+)') +KIWIX_URL_PARSER = re.compile(r'https:\/\/download\.kiwix\.org\/zim\/(.+?)\/(.+?)[_-](\w{2,3})([_-].+)') +KIWIX_URL_NO_FLAVOR_PARSER = re.compile(r'https:\/\/download\.kiwix\.org\/zim\/(.+?)\/(.+)[_-]([a-zA-Z]{2,3})') def zim_download_url_to_name(url: str) -> Tuple[str, str]: - _, project, language, flavor = KIWIX_URL_PARSER.match(url).groups() + try: + _, project, language, flavor = KIWIX_URL_PARSER.match(url).groups() + except AttributeError: + # May not have a "flavor". + _, project, language = KIWIX_URL_NO_FLAVOR_PARSER.match(url).groups() + flavor = None if project == 'wikipedia' and flavor == '_all_maxi_': name = 'Wikipedia (with images)' elif project == 'wikipedia' and flavor == '_all_nopic_': @@ -420,6 +438,18 @@ def zim_download_url_to_name(url: str) -> Tuple[str, str]: name = 'Arduino (Stack Exchange)' elif project == '3dprinting.stackexchange.com' and flavor == '_all_': name = '3D Printing (Stack Exchange)' + elif project == 'mdwiki' and flavor == '_all_': + name = 'MD Wiki (Wiki Project Med Foundation)' + elif project == 'wikipedia' and flavor == '_medicine_': + name = 'WikiMed Medical Encyclopedia' + elif project == 'zimgit-post-disaster' and flavor is None: + name = 'Post Disaster Resource Library' + elif project == 'fas-military-medicine' and flavor is None: + name = 'Military Medicine' + elif project == 'wikem' and flavor == '_all_maxi_': + name = 'WikEm (Global Emergency Medicine Wiki)' + elif project == 'health.stackexchange.com' and flavor == '_all_': + name = 'Health (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 159b47cb..cb7965e2 100644 --- a/modules/zim/test/test_lib.py +++ b/modules/zim/test/test_lib.py @@ -281,6 +281,18 @@ def test_zim_tag_migration(test_session, test_directory, zim_factory, tag_factor ('Arduino (Stack Exchange)', 'en')), ('https://download.kiwix.org/zim/stack_exchange/3dprinting.stackexchange.com_en_all_', ('3D Printing (Stack Exchange)', 'en')), + ('https://download.kiwix.org/zim/other/mdwiki_en_all_', + ('MD Wiki (Wiki Project Med Foundation)', 'en')), + ('https://download.kiwix.org/zim/wikipedia/wikipedia_bpy_medicine_', + ('WikiMed Medical Encyclopedia', 'bpy')), + ('https://download.kiwix.org/zim/other/zimgit-post-disaster_en_', + ('Post Disaster Resource Library', 'en')), + ('https://download.kiwix.org/zim/zimit/fas-military-medicine_en_', + ('Military Medicine', 'en')), + ('https://download.kiwix.org/zim/other/wikem_en_all_maxi_', + ('WikEm (Global Emergency Medicine Wiki)', 'en')), + ('https://download.kiwix.org/zim/stack_exchange/health.stackexchange.com_en_all_', + ('Health (Stack Exchange)', 'en')), ] ) def test_zim_download_url_to_name(url, expected):