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]

\n", - "\n", - "> 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": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "show_doc(parse_query)" ] @@ -223,24 +193,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'q': 'wragge',\n", - " 'l-artType': 'newspapers',\n", - " 'l-state': ['Queensland'],\n", - " 'l-category': ['Article'],\n", - " 'l-illustrated': 'true',\n", - " 'l-illtype': ['Cartoon'],\n", - " 'category': 'newspaper'}" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "params = parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-state=Queensland&l-category=Article&l-illustrationType=Cartoon', 3)\n", "params" @@ -379,18 +332,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'q': 'wragge date:[1901 TO 1903]', 'zone': 'newspaper'}" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge%20date%3A%5B1901%20TO%201903%5D&l-artType=newspapers')" ] @@ -470,18 +412,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'q': 'wragge', 'zone': 'newspaper', 'l-decade': ['190']}" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-decade=190')" ] @@ -497,18 +428,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'q': 'wragge', 'zone': 'newspaper', 'l-decade': ['190'], 'l-year': ['1903']}" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-decade=190&l-year=1903')" ] @@ -542,7 +462,7 @@ "metadata": {}, "outputs": [], "source": [ - "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')" ] }, { @@ -910,7 +830,7 @@ "outputs": [], "source": [ "params = parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-illustrationType=Photo', 3)\n", - "assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illtype': ['Photo'], 'l-artType': 'newspapers'} == params\n", + "assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illustrationType': ['Photo'], 'l-artType': 'newspapers'} == params\n", "assert query_api(params) == 200" ] }, @@ -928,7 +848,7 @@ "outputs": [], "source": [ "params = parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge&l-artType=newspapers&l-word=1000%2B%20Words', 3)\n", - "assert {'q': 'wragge', 'category': 'newspaper', 'l-word': ['1000+ Words'], 'l-artType': 'newspapers'} == params\n", + "assert {'q': 'wragge', 'category': 'newspaper', 'l-wordCount': '1000+ Words', 'l-artType': 'newspapers'} == params\n", "assert query_api(params) == 200" ] }, @@ -1079,7 +999,7 @@ "outputs": [], "source": [ "params = parse_query('https://trove.nla.gov.au/search/advanced/category/newspapers?keyword=wragge&l-advArtType=newspapers&l-advIllustrationType=Photo', 3)\n", - "assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illtype': ['Photo'], 'l-artType': 'newspapers'} == params\n", + "assert {'q': 'wragge', 'category': 'newspaper', 'l-illustrated': 'true', 'l-illustrationType': ['Photo'], 'l-artType': 'newspapers'} == params\n", "assert query_api(params) == 200" ] }, @@ -1097,7 +1017,7 @@ "outputs": [], "source": [ "params = parse_query('https://trove.nla.gov.au/search/advanced/category/newspapers?keyword=wragge&l-advArtType=newspapers&l-advWord=100%20-%201000%20Words', 3)\n", - "assert {'q': 'wragge', 'category': 'newspaper', 'l-word': '100 - 1000 Words', 'l-artType': 'newspapers'} == params\n", + "assert {'q': 'wragge', 'category': 'newspaper', 'l-wordCount': '100 - 1000 Words', 'l-artType': 'newspapers'} == params\n", "assert query_api(params) == 200" ] }, diff --git a/README.md b/README.md index 0a8a02a..aded824 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ parse_query('https://trove.nla.gov.au/search/category/newspapers?keyword=wragge& 'l-state': ['Queensland'], 'l-category': ['Article'], 'l-illustrated': 'true', - 'l-illtype': ['Cartoon'], + 'l-illustrationType': ['Cartoon'], 'category': 'newspaper'} diff --git a/docs/index.html b/docs/index.html index db31d73..374f18a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -83,7 +83,7 @@

How to use diff --git a/docs/parser.html b/docs/parser.html index 7a52803..5b74c89 100644 --- a/docs/parser.html +++ b/docs/parser.html @@ -131,28 +131,6 @@

Basic usage -
-
- -
- - - -
-
{'q': 'wragge',
- 'l-artType': 'newspapers',
- 'l-state': ['Queensland'],
- 'l-category': ['Article'],
- 'l-illustrated': 'true',
- 'l-illtype': ['Cartoon'],
- 'category': 'newspaper'}
-
- -
- -
-
- {% endraw %} @@ -316,22 +294,6 @@

Simple search with facets -
- -
- - - -
-
{'q': 'wragge date:[1901 TO 1903]', 'zone': 'newspaper'}
-
- -
- -
- - {% endraw %} @@ -452,22 +414,6 @@

Simple search with facets -
- -
- - - -
-
{'q': 'wragge', 'zone': 'newspaper', 'l-decade': ['190']}
-
- -
- -
- - {% endraw %} @@ -492,22 +438,6 @@

Simple search with facets -
- -
- - - -
-
{'q': 'wragge', 'zone': 'newspaper', 'l-decade': ['190'], 'l-year': ['1903']}
-
- -
- -
- - {% endraw %} @@ -549,7 +479,7 @@

Simple search with facets
-
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')
 
@@ -1082,7 +1012,7 @@

Simple search with facets
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
 
@@ -1108,7 +1038,7 @@

Simple search with facets
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
 
@@ -1322,7 +1252,7 @@