|
427 | 427 | " * a list of paths to the image/media files (filename is used as title)\n",
|
428 | 428 | " * a list of dicts, each containing `title`, and `path` values\n",
|
429 | 429 | " \n",
|
| 430 | + " The path values can either be strings or pathlib Paths.\n", |
| 431 | + " \n", |
430 | 432 | " Returns: \n",
|
431 | 433 | " * the modified payload dict\n",
|
432 | 434 | " '''\n",
|
|
435 | 437 | " for index, media_file in enumerate(media_files):\n",
|
436 | 438 | " if isinstance(media_file, dict):\n",
|
437 | 439 | " title = media_file['title']\n",
|
438 |
| - " path = media_file['path']\n", |
| 440 | + " path = Path(media_file['path'])\n", |
439 | 441 | " else:\n",
|
440 |
| - " title = media_file[:-4]\n", |
441 |
| - " path = media_file\n", |
| 442 | + " path = Path(media_file)\n", |
| 443 | + " title = path.name\n", |
442 | 444 | " payload['o:media'].append({'o:ingester': 'upload', 'file_index': str(index), 'o:item': {}, 'dcterms:title': [{'property_id': 1, '@value': title, 'type': 'literal'}]})\n",
|
443 |
| - " files[f'file[{index}]'] = Path(path).read_bytes()\n", |
| 445 | + " files[f'file[{index}]'] = path.read_bytes()\n", |
444 | 446 | " files['data'] = (None, json.dumps(payload), 'application/json')\n",
|
445 | 447 | " return files"
|
446 | 448 | ]
|
|
1846 | 1848 | "data": {
|
1847 | 1849 | "text/plain": [
|
1848 | 1850 | "{'@context': 'http://timsherratt.org/collections/api-context',\n",
|
1849 |
| - " '@id': 'http://timsherratt.org/collections/api/items/730',\n", |
| 1851 | + " '@id': 'http://timsherratt.org/collections/api/items/763',\n", |
1850 | 1852 | " '@type': 'o:Item',\n",
|
1851 |
| - " 'o:id': 730,\n", |
| 1853 | + " 'o:id': 763,\n", |
1852 | 1854 | " 'o:is_public': True,\n",
|
1853 | 1855 | " 'o:owner': {'@id': 'http://timsherratt.org/collections/api/users/1',\n",
|
1854 | 1856 | " 'o:id': 1},\n",
|
|
1858 | 1860 | " 'o:thumbnail': None,\n",
|
1859 | 1861 | " 'o:title': 'The Bendigo Independent (Vic. : 1891 - 1918)',\n",
|
1860 | 1862 | " 'thumbnail_display_urls': {'large': None, 'medium': None, 'square': None},\n",
|
1861 |
| - " 'o:created': {'@value': '2022-01-26T04:46:55+00:00',\n", |
| 1863 | + " 'o:created': {'@value': '2022-01-27T05:35:36+00:00',\n", |
1862 | 1864 | " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n",
|
1863 |
| - " 'o:modified': {'@value': '2022-01-26T04:46:55+00:00',\n", |
| 1865 | + " 'o:modified': {'@value': '2022-01-27T05:35:36+00:00',\n", |
1864 | 1866 | " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n",
|
1865 | 1867 | " 'o:media': [],\n",
|
1866 | 1868 | " 'o:item_set': [],\n",
|
|
2071 | 2073 | " '@value': \"MR WRAGGE'S PREDICTION. RENEWAL OF CYCLONE FORETOLD.\"}],\n",
|
2072 | 2074 | " 'schema:isPartOf': [{'property_id': 736,\n",
|
2073 | 2075 | " 'type': 'resource:item',\n",
|
2074 |
| - " '@id': 'http://timsherratt.org/collections/api/items/730',\n", |
2075 |
| - " 'value_resource_id': 730,\n", |
| 2076 | + " '@id': 'http://timsherratt.org/collections/api/items/763',\n", |
| 2077 | + " 'value_resource_id': 763,\n", |
2076 | 2078 | " 'value_resource_name': 'items'}],\n",
|
2077 | 2079 | " 'schema:datePublished': [{'property_id': 928,\n",
|
2078 | 2080 | " 'type': 'numeric:timestamp',\n",
|
|
2105 | 2107 | "outputs": [],
|
2106 | 2108 | "source": [
|
2107 | 2109 | "# Create a list of paths pointing to media files\n",
|
| 2110 | + "# The paths can be strings or pathlib Paths\n", |
2108 | 2111 | "media_files = ['media/nla.news-article226799674-24144902.jpg']\n",
|
2109 | 2112 | "\n",
|
2110 | 2113 | "# Include the media files when we upload the payload\n",
|
|
2127 | 2130 | "data": {
|
2128 | 2131 | "text/plain": [
|
2129 | 2132 | "{'@context': 'http://timsherratt.org/collections/api-context',\n",
|
2130 |
| - " '@id': 'http://timsherratt.org/collections/api/items/731',\n", |
| 2133 | + " '@id': 'http://timsherratt.org/collections/api/items/766',\n", |
2131 | 2134 | " '@type': 'o:Item',\n",
|
2132 |
| - " 'o:id': 731,\n", |
| 2135 | + " 'o:id': 766,\n", |
2133 | 2136 | " 'o:is_public': True,\n",
|
2134 | 2137 | " 'o:owner': {'@id': 'http://timsherratt.org/collections/api/users/1',\n",
|
2135 | 2138 | " 'o:id': 1},\n",
|
|
2138 | 2141 | " 'o:id': 4},\n",
|
2139 | 2142 | " 'o:thumbnail': None,\n",
|
2140 | 2143 | " 'o:title': \"MR WRAGGE'S PREDICTION. RENEWAL OF CYCLONE FORETOLD.\",\n",
|
2141 |
| - " 'thumbnail_display_urls': {'large': 'http://timsherratt.org/collections/files/large/aa9ef3fe881ee92c46bc8f1500d7f9fa9f3d6bb4.jpg',\n", |
2142 |
| - " 'medium': 'http://timsherratt.org/collections/files/medium/aa9ef3fe881ee92c46bc8f1500d7f9fa9f3d6bb4.jpg',\n", |
2143 |
| - " 'square': 'http://timsherratt.org/collections/files/square/aa9ef3fe881ee92c46bc8f1500d7f9fa9f3d6bb4.jpg'},\n", |
2144 |
| - " 'o:created': {'@value': '2022-01-26T04:47:02+00:00',\n", |
| 2144 | + " 'thumbnail_display_urls': {'large': 'http://timsherratt.org/collections/files/large/370fd463d1743fc81fa00d71448f294e7aec7643.jpg',\n", |
| 2145 | + " 'medium': 'http://timsherratt.org/collections/files/medium/370fd463d1743fc81fa00d71448f294e7aec7643.jpg',\n", |
| 2146 | + " 'square': 'http://timsherratt.org/collections/files/square/370fd463d1743fc81fa00d71448f294e7aec7643.jpg'},\n", |
| 2147 | + " 'o:created': {'@value': '2022-01-27T05:37:15+00:00',\n", |
2145 | 2148 | " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n",
|
2146 |
| - " 'o:modified': {'@value': '2022-01-26T04:47:02+00:00',\n", |
| 2149 | + " 'o:modified': {'@value': '2022-01-27T05:37:15+00:00',\n", |
2147 | 2150 | " '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'},\n",
|
2148 |
| - " 'o:media': [{'@id': 'http://timsherratt.org/collections/api/media/732',\n", |
2149 |
| - " 'o:id': 732}],\n", |
| 2151 | + " 'o:media': [{'@id': 'http://timsherratt.org/collections/api/media/767',\n", |
| 2152 | + " 'o:id': 767}],\n", |
2150 | 2153 | " 'o:item_set': [],\n",
|
2151 | 2154 | " 'o:site': [],\n",
|
2152 | 2155 | " 'schema:name': [{'type': 'literal',\n",
|
|
2164 | 2167 | " 'property_id': 736,\n",
|
2165 | 2168 | " 'property_label': 'isPartOf',\n",
|
2166 | 2169 | " 'is_public': True,\n",
|
2167 |
| - " '@id': 'http://timsherratt.org/collections/api/items/730',\n", |
2168 |
| - " 'value_resource_id': 730,\n", |
| 2170 | + " '@id': 'http://timsherratt.org/collections/api/items/763',\n", |
| 2171 | + " 'value_resource_id': 763,\n", |
2169 | 2172 | " 'value_resource_name': 'items',\n",
|
2170 | 2173 | " 'url': None,\n",
|
2171 | 2174 | " 'display_title': 'The Bendigo Independent (Vic. : 1891 - 1918)'}],\n",
|
|
2193 | 2196 | "\n",
|
2194 | 2197 | "* update and delete methods"
|
2195 | 2198 | ]
|
| 2199 | + }, |
| 2200 | + { |
| 2201 | + "cell_type": "code", |
| 2202 | + "execution_count": null, |
| 2203 | + "metadata": {}, |
| 2204 | + "outputs": [], |
| 2205 | + "source": [] |
2196 | 2206 | }
|
2197 | 2207 | ],
|
2198 | 2208 | "metadata": {
|
|
0 commit comments