diff --git a/00_parser.ipynb b/00_parser.ipynb index d23c016..4cebe78 100644 --- a/00_parser.ipynb +++ b/00_parser.ipynb @@ -22,16 +22,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The dotenv extension is already loaded. To reload it, use:\n", - " %reload_ext dotenv\n" - ] - } - ], + "outputs": [], "source": [ "#hide\n", "from nbdev.showdoc import *\n", @@ -90,7 +81,7 @@ " new_params = parse_qs(parsed_url.query)\n", " else:\n", " # These params can be accepted as is.\n", - " safe = ['l-category', 'l-title', 'l-decade', 'l-year', 'l-month', 'l-state', 'l-word', 'include']\n", + " safe = ['l-category', 'l-title', 'l-decade', 'l-year', 'l-month', 'l-state', 'include']\n", " new_params = {}\n", " dates = {}\n", " keywords = []\n", @@ -102,8 +93,11 @@ " new_params[key].append(value)\n", " except KeyError:\n", " new_params[key] = [value]\n", - " elif key == 'l-advWord':\n", - " new_params['l-word'] = value\n", + " elif key in ['l-word', 'l-advWord']:\n", + " if api_version == 2:\n", + " new_params['l-word'] = value\n", + " elif api_version == 3:\n", + " new_params['l-wordCount'] = value\n", " elif key == 'l-advstate':\n", " try:\n", " new_params['l-state'].append(value)\n", @@ -121,10 +115,10 @@ " new_params['l-title'] = [value]\n", " elif key in ['l-illustrationType', 'l-advIllustrationType']:\n", " new_params['l-illustrated'] = 'true'\n", - " try:\n", - " new_params['l-illtype'].append(value)\n", - " except KeyError:\n", + " if api_version == 2:\n", " new_params['l-illtype'] = [value]\n", + " elif api_version == 3:\n", + " new_params['l-illustrationType'] = [value]\n", " elif key == 'date.from':\n", " dates['from'] = value\n", " elif key == 'date.to':\n", @@ -174,31 +168,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "
parse_query
[source]parse_query
(**`query`**, **`api_version`**=*`2`*)\n",
- "\n",
- "Converts the parameters of a search using the Trove web interface into a form the API will understand.\n",
- "\n",
- "Parameters: \n",
- "* `query` – the url of a search in the Trove newspapers & gazettes category\n",
- "* `api_version` – Trove API version (default is 2)\n",
- "\n",
- "Returns: \n",
- "* a dict containing the parameters (multiple values will be in a list)"
- ],
- "text/plain": [
- "assert {'q': 'wragge', 'zone': 'newspaper', 'l-word': ['1000+ Words']} == parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-word=1000%2B%20Words')
+assert {'q': 'wragge', 'zone': 'newspaper', 'l-word': '1000+ Words'} == parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-word=1000%2B%20Words')
params = parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-illustrationType=Photo', 3)
-assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illtype': ['Photo'], 'l-artType': 'newspapers'} == params
+assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illustrationType': ['Photo'], 'l-artType': 'newspapers'} == params
assert query_api(params) == 200
params = parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-word=1000%2B%20Words', 3)
-assert {'q': 'wragge', 'category': 'newspaper', 'l-word': ['1000+ Words'], 'l-artType': 'newspapers'} == params
+assert {'q': 'wragge', 'category': 'newspaper', 'l-wordCount': '1000+ Words', 'l-artType': 'newspapers'} == params
assert query_api(params) == 200
params = parse_query('https://trove.nla.gov.au/search/advanced/category/newspapers?keyword=wragge&l-advArtType=newspapers&l-advIllustrationType=Photo', 3)
-assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illtype': ['Photo'], 'l-artType': 'newspapers'} == params
+assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illustrationType': ['Photo'], 'l-artType': 'newspapers'} == params
assert query_api(params) == 200
params = parse_query('https://trove.nla.gov.au/search/advanced/category/newspapers?keyword=wragge&l-advArtType=newspapers&l-advWord=100%20-%201000%20Words', 3)
-assert {'q': 'wragge', 'category': 'newspaper', 'l-word': '100 - 1000 Words', 'l-artType': 'newspapers'} == params
+assert {'q': 'wragge', 'category': 'newspaper', 'l-wordCount': '100 - 1000 Words', 'l-artType': 'newspapers'} == params
assert query_api(params) == 200