diff --git a/api.ipynb b/api.ipynb index 6567ae2..2856bcd 100644 --- a/api.ipynb +++ b/api.ipynb @@ -427,6 +427,8 @@ " * a list of paths to the image/media files (filename is used as title)\n", " * a list of dicts, each containing `title`, and `path` values\n", " \n", + " The path values can either be strings or pathlib Paths.\n", + " \n", " Returns: \n", " * the modified payload dict\n", " '''\n", @@ -435,12 +437,12 @@ " for index, media_file in enumerate(media_files):\n", " if isinstance(media_file, dict):\n", " title = media_file['title']\n", - " path = media_file['path']\n", + " path = Path(media_file['path'])\n", " else:\n", - " title = media_file[:-4]\n", - " path = media_file\n", + " path = Path(media_file)\n", + " title = path.name\n", " payload['o:media'].append({'o:ingester': 'upload', 'file_index': str(index), 'o:item': {}, 'dcterms:title': [{'property_id': 1, '@value': title, 'type': 'literal'}]})\n", - " files[f'file[{index}]'] = Path(path).read_bytes()\n", + " files[f'file[{index}]'] = path.read_bytes()\n", " files['data'] = (None, json.dumps(payload), 'application/json')\n", " return files" ] @@ -1846,9 +1848,9 @@ "data": { "text/plain": [ "{'@context': 'http://timsherratt.org/collections/api-context',\n", - " '@id': 'http://timsherratt.org/collections/api/items/730',\n", + " '@id': 'http://timsherratt.org/collections/api/items/763',\n", " '@type': 'o:Item',\n", - " 'o:id': 730,\n", + " 'o:id': 763,\n", " 'o:is_public': True,\n", " 'o:owner': {'@id': 'http://timsherratt.org/collections/api/users/1',\n", " 'o:id': 1},\n", @@ -1858,9 +1860,9 @@ " 'o:thumbnail': None,\n", " 'o:title': 'The Bendigo Independent (Vic. : 1891 - 1918)',\n", " 'thumbnail_display_urls': {'large': None, 'medium': None, 'square': None},\n", - " 'o:created': {'@value': '2022-01-26T04:46:55+00:00',\n", + " 'o:created': {'@value': '2022-01-27T05:35:36+00:00',\n", " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n", - " 'o:modified': {'@value': '2022-01-26T04:46:55+00:00',\n", + " 'o:modified': {'@value': '2022-01-27T05:35:36+00:00',\n", " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n", " 'o:media': [],\n", " 'o:item_set': [],\n", @@ -2071,8 +2073,8 @@ " '@value': \"MR WRAGGE'S PREDICTION. RENEWAL OF CYCLONE FORETOLD.\"}],\n", " 'schema:isPartOf': [{'property_id': 736,\n", " 'type': 'resource:item',\n", - " '@id': 'http://timsherratt.org/collections/api/items/730',\n", - " 'value_resource_id': 730,\n", + " '@id': 'http://timsherratt.org/collections/api/items/763',\n", + " 'value_resource_id': 763,\n", " 'value_resource_name': 'items'}],\n", " 'schema:datePublished': [{'property_id': 928,\n", " 'type': 'numeric:timestamp',\n", @@ -2105,6 +2107,7 @@ "outputs": [], "source": [ "# Create a list of paths pointing to media files\n", + "# The paths can be strings or pathlib Paths\n", "media_files = ['media/nla.news-article226799674-24144902.jpg']\n", "\n", "# Include the media files when we upload the payload\n", @@ -2127,9 +2130,9 @@ "data": { "text/plain": [ "{'@context': 'http://timsherratt.org/collections/api-context',\n", - " '@id': 'http://timsherratt.org/collections/api/items/731',\n", + " '@id': 'http://timsherratt.org/collections/api/items/766',\n", " '@type': 'o:Item',\n", - " 'o:id': 731,\n", + " 'o:id': 766,\n", " 'o:is_public': True,\n", " 'o:owner': {'@id': 'http://timsherratt.org/collections/api/users/1',\n", " 'o:id': 1},\n", @@ -2138,15 +2141,15 @@ " 'o:id': 4},\n", " 'o:thumbnail': None,\n", " 'o:title': \"MR WRAGGE'S PREDICTION. RENEWAL OF CYCLONE FORETOLD.\",\n", - " 'thumbnail_display_urls': {'large': 'http://timsherratt.org/collections/files/large/aa9ef3fe881ee92c46bc8f1500d7f9fa9f3d6bb4.jpg',\n", - " 'medium': 'http://timsherratt.org/collections/files/medium/aa9ef3fe881ee92c46bc8f1500d7f9fa9f3d6bb4.jpg',\n", - " 'square': 'http://timsherratt.org/collections/files/square/aa9ef3fe881ee92c46bc8f1500d7f9fa9f3d6bb4.jpg'},\n", - " 'o:created': {'@value': '2022-01-26T04:47:02+00:00',\n", + " 'thumbnail_display_urls': {'large': 'http://timsherratt.org/collections/files/large/370fd463d1743fc81fa00d71448f294e7aec7643.jpg',\n", + " 'medium': 'http://timsherratt.org/collections/files/medium/370fd463d1743fc81fa00d71448f294e7aec7643.jpg',\n", + " 'square': 'http://timsherratt.org/collections/files/square/370fd463d1743fc81fa00d71448f294e7aec7643.jpg'},\n", + " 'o:created': {'@value': '2022-01-27T05:37:15+00:00',\n", " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n", - " 'o:modified': {'@value': '2022-01-26T04:47:02+00:00',\n", + " 'o:modified': {'@value': '2022-01-27T05:37:15+00:00',\n", " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n", - " 'o:media': [{'@id': 'http://timsherratt.org/collections/api/media/732',\n", - " 'o:id': 732}],\n", + " 'o:media': [{'@id': 'http://timsherratt.org/collections/api/media/767',\n", + " 'o:id': 767}],\n", " 'o:item_set': [],\n", " 'o:site': [],\n", " 'schema:name': [{'type': 'literal',\n", @@ -2164,8 +2167,8 @@ " 'property_id': 736,\n", " 'property_label': 'isPartOf',\n", " 'is_public': True,\n", - " '@id': 'http://timsherratt.org/collections/api/items/730',\n", - " 'value_resource_id': 730,\n", + " '@id': 'http://timsherratt.org/collections/api/items/763',\n", + " 'value_resource_id': 763,\n", " 'value_resource_name': 'items',\n", " 'url': None,\n", " 'display_title': 'The Bendigo Independent (Vic. : 1891 - 1918)'}],\n", @@ -2193,6 +2196,13 @@ "\n", "* update and delete methods" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/docs/api.html b/docs/api.html index f727a1e..1ac46fd 100644 --- a/docs/api.html +++ b/docs/api.html @@ -1133,6 +1133,7 @@
OmekaAPICl
a list of paths to the image/media files (filename is used as title)
a list of dicts, each containing title
, and path
values
+The path values can either be strings or pathlib Paths.
Returns:
- the modified payload dict
@@ -1865,9 +1866,9 @@ Example: adding a newspa