|
30 | 30 | "cell_type": "code", |
31 | 31 | "execution_count": 2, |
32 | 32 | "metadata": {}, |
33 | | - "outputs": [ |
34 | | - { |
35 | | - "name": "stderr", |
36 | | - "output_type": "stream", |
37 | | - "text": [ |
38 | | - "C:\\Users\\tar12555\\AppData\\Local\\ESRI\\conda\\envs\\pyapi-dev\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n", |
39 | | - "C:\\Users\\tar12555\\AppData\\Local\\ESRI\\conda\\envs\\pyapi-dev\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.23-246-g3d31191b-gcc_10_3_0.dll\n", |
40 | | - "C:\\Users\\tar12555\\AppData\\Local\\ESRI\\conda\\envs\\pyapi-dev\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.23-gcc_10_3_0.dll\n", |
41 | | - " warnings.warn(\"loaded more than 1 DLL from .libs:\"\n", |
42 | | - "C:\\Users\\tar12555\\AppData\\Local\\ESRI\\conda\\envs\\pyapi-dev\\lib\\site-packages\\scipy\\__init__.py:138: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.25.2)\n", |
43 | | - " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion} is required for this version of \"\n" |
44 | | - ] |
45 | | - } |
46 | | - ], |
| 33 | + "outputs": [], |
47 | 34 | "source": [ |
48 | 35 | "import os\n", |
49 | 36 | "import datetime as dt\n", |
|
64 | 51 | "cell_type": "markdown", |
65 | 52 | "metadata": {}, |
66 | 53 | "source": [ |
67 | | - "As mentioned in the [`gis module`](https://developers.arcgis.com/python/guide/the-gis-module/) guide, the Python API uses [Resource Manager classes](https://developers.arcgis.com/python/guide/the-gis-module/) to manage Web GIS users, groups, datastores, and content. You access the [`UserManager`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager), [`GroupManager`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#groupmanager) and [`ContentManager`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager) classes as the `users`, `groups`, and `content` properties of the [`GIS`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#gis), respectively. (See [`Helper objects`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#gis) for details.)\n", |
| 54 | + "As mentioned in the [`gis module`](/python/guide/the-gis-module/) guide, the Python API uses [Resource Manager classes](/python/guide/the-gis-module/) to manage Web GIS users, groups, datastores, and content. You access the [`UserManager`](/python/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager), [`GroupManager`](/python/api-reference/arcgis.gis.toc.html#groupmanager) and [`ContentManager`](/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager) classes as the `users`, `groups`, and `content` properties of the [`GIS`](/python/api-reference/arcgis.gis.toc.html#gis), respectively.\n", |
68 | 55 | "\n", |
69 | | - "Each resource manager implements the [ArcGIS REST API](https://developers.arcgis.com/rest/users-groups-and-items/search.htm) `search` operation as a method. For example, `gis.content.search()`. It's important to understand that the `search` mechanism uses many different inputs to find possible matches, ranks them and returns appropriate results. The `search` becomes ideal for human interaction, but `fuzzy` when looking for specific records programmatically. The search results are non-deterministic. Using `search` may not necessarily be the best approach for finding specific items, but more a group of items from which to further filter. \n", |
| 56 | + "Each search resource manager, for example _gis.content.search()_, implements the [ArcGIS REST API](/rest/users-groups-and-items/search.htm) `search` operation. It's important to understand that the `search` mechanism uses many different inputs to find possible matches, ranks them and returns appropriate results. The `search` becomes ideal for human interaction, but `fuzzy` when looking for specific records programmatically. The search results are non-deterministic. Using `search` may not necessarily be the best approach for finding specific items, but more a group of items from which to further filter. \n", |
70 | 57 | "\n", |
71 | 58 | "It's also important to know that using `search` programmatically, like with the Python API, does not correspond identically to searching with an application written in a different language. The various `search` options in the ArcGIS Online or Portal for ArcGIS Enterprise interfaces work differently than the Python API resource managers' `search`. Different applications may use different inputs. The relationship between a content `search` in one application, like a Portal or ArcGIS Online viewer, is not one-to-one with a content search using the Python API even when logged in as the same user.\n", |
72 | 59 | "\n", |
|
75 | 62 | }, |
76 | 63 | { |
77 | 64 | "cell_type": "code", |
78 | | - "execution_count": 2, |
| 65 | + "execution_count": 3, |
79 | 66 | "metadata": {}, |
80 | 67 | "outputs": [], |
81 | 68 | "source": [ |
|
203 | 190 | }, |
204 | 191 | { |
205 | 192 | "cell_type": "code", |
206 | | - "execution_count": 4, |
| 193 | + "execution_count": 37, |
207 | 194 | "metadata": {}, |
208 | 195 | "outputs": [], |
209 | 196 | "source": [ |
210 | | - "day_start = dt.datetime(2019, 5, 30, 0, 0, 0, 0)\n", |
211 | | - "day_end = dt.datetime(2019, 5, 30, 23, 59, 59, 999999)\n", |
| 197 | + "day_start = dt.datetime(2023, 9, 21, 0, 0, 0, 0)\n", |
| 198 | + "day_end = dt.datetime(2023, 9, 21, 23, 59, 59, 999999)\n", |
212 | 199 | "\n", |
213 | 200 | "start_timestamp = int(day_start.timestamp() * 1000)\n", |
214 | 201 | "end_timestamp = int(day_end.timestamp() * 1000)" |
|
223 | 210 | }, |
224 | 211 | { |
225 | 212 | "cell_type": "code", |
226 | | - "execution_count": 5, |
| 213 | + "execution_count": 40, |
227 | 214 | "metadata": {}, |
228 | 215 | "outputs": [], |
229 | 216 | "source": [ |
230 | | - "content_published_53019 = [item\n", |
231 | | - " for item in gis.content.search(query=\"* AND \\\n", |
232 | | - " owner:\" + gis.users.me.username,\n", |
233 | | - " max_items=50)\n", |
234 | | - " if item.created > start_timestamp \n", |
235 | | - " and item.created < end_timestamp]" |
| 217 | + "content_published_92123 = [\n", |
| 218 | + " item\n", |
| 219 | + " for item in gis.content.search(\n", |
| 220 | + " query=f\"owner:{gis.users.me.username}\",\n", |
| 221 | + " max_items=100) \n", |
| 222 | + " if item.created > start_timestamp\n", |
| 223 | + " and item.created < end_timestamp]" |
236 | 224 | ] |
237 | 225 | }, |
238 | 226 | { |
|
244 | 232 | }, |
245 | 233 | { |
246 | 234 | "cell_type": "code", |
247 | | - "execution_count": 6, |
| 235 | + "execution_count": 41, |
248 | 236 | "metadata": {}, |
249 | 237 | "outputs": [], |
250 | 238 | "source": [ |
|
254 | 242 | }, |
255 | 243 | { |
256 | 244 | "cell_type": "code", |
257 | | - "execution_count": 7, |
| 245 | + "execution_count": 45, |
258 | 246 | "metadata": {}, |
259 | 247 | "outputs": [ |
260 | 248 | { |
261 | 249 | "name": "stdout", |
262 | 250 | "output_type": "stream", |
263 | 251 | "text": [ |
264 | | - "Item Title Item Type Published \n" |
| 252 | + "Item Title Item Type Published \n", |
| 253 | + "425e9ee3dd774bbe8d472b73e9cadbd2 File Geodatabase September 21 2023 at 10:45.47 AM \n", |
| 254 | + "ad37530ecc3744e8b3a9db52adde6408 File Geodatabase September 21 2023 at 10:43.44 AM \n" |
265 | 255 | ] |
266 | 256 | } |
267 | 257 | ], |
|
271 | 261 | "publish = \"Published\"\n", |
272 | 262 | "print(f\"{title:40}{item_type:25}{publish:40}\")\n", |
273 | 263 | "\n", |
274 | | - "for content in content_published_53019:\n", |
275 | | - " print(f\" {content.title:<40} {content.type:25} {readable_date(content.created):40}\")" |
| 264 | + "for content in content_published_92123:\n", |
| 265 | + " print(f\"{content.title:<40}{content.type:25}{readable_date(content.created):40}\")" |
276 | 266 | ] |
277 | 267 | }, |
278 | 268 | { |
|
1435 | 1425 | "source": [ |
1436 | 1426 | "## Creating new content\n", |
1437 | 1427 | "\n", |
1438 | | - "To create new items on your GIS, you use the [`add()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.add) method on a `ContentManager` instance. Again, rather than creating an instance of the `ContentManager` directly, the Python API implements the class as the `content` property of your `GIS` object.\n", |
| 1428 | + "To create new items on your GIS, use the [`add()`](/api-reference/arcgis.gis.toc.html#arcgis.gis._impl._content_manager.Folder.add) method on a [`Folder`](/python/api-reference/arcgis.gis.toc.html#folder) instance. You can get an individual _folder_ using the [`Folders.get()`](/python/api-reference/arcgis.gis.toc.html#arcgis.gis._impl._content_manager.Folders.get) method.\n", |
1439 | 1429 | "\n", |
1440 | | - "The `add()` method accepts a dictionary containing the properties of the item to be created. The optional `data` parameter accepts a string path to a file. You can use the optional `metadata` parameter to specify an XML file containing metadata information.\n", |
| 1430 | + "The `add()` method accepts a dictionary containing the properties of the item to be created. The optional `file`, `text`, `url`, and `data_url` parameters accept input to add the actual content. \n", |
1441 | 1431 | "\n", |
1442 | | - "All content you add this way is added to the authenticated user's contents. Let us connect to our Enterprise instance, add a csv file as an item and then publish a feature layer from it.\n", |
| 1432 | + "All content you add this way is added to the authenticated user's dolswe. Let us connect to our Enterprise instance, add a csv file as an item and then publish a feature layer from it.\n", |
1443 | 1433 | "\n", |
1444 | 1434 | "For example, set up a path to the data:\n", |
1445 | 1435 | "`data_path = os.path.join(r\"<your_drive>:\\\\\", \"path\", \"to\", \"data\")`" |
|
1492 | 1482 | " 'tags':'arcgis, python, earthquake, natural disaster, emergency'}\n", |
1493 | 1483 | "thumbnail_path = os.path.join(data_path, \"earthquake.png\")\n", |
1494 | 1484 | "\n", |
1495 | | - "earthquake_csv_item = gis.content.add(item_properties=csv_properties, data=csv_path,\n", |
1496 | | - " thumbnail = thumbnail_path)" |
| 1485 | + "root_folder = gis.content.folders.get()\n", |
| 1486 | + "earthquake_csv_item = root_folder.add(\n", |
| 1487 | + " item_properties=csv_properties, \n", |
| 1488 | + " data=csv_path,\n", |
| 1489 | + " thumbnail = thumbnail_path\n", |
| 1490 | + ").result()" |
1497 | 1491 | ] |
1498 | 1492 | }, |
1499 | 1493 | { |
|
1617 | 1611 | { |
1618 | 1612 | "cell_type": "markdown", |
1619 | 1613 | "metadata": { |
1620 | | - "collapsed": true |
| 1614 | + "collapsed": true, |
| 1615 | + "jupyter": { |
| 1616 | + "outputs_hidden": true |
| 1617 | + } |
1621 | 1618 | }, |
1622 | 1619 | "source": [ |
1623 | 1620 | "<a id=\"importing-data-from-a-pandas-data-frame\"></a>\n", |
|
2325 | 2322 | " 'tags': 'arcgis python api, pandas, csv',\n", |
2326 | 2323 | " 'text':ports_json,\n", |
2327 | 2324 | " 'type':'Feature Collection'}\n", |
2328 | | - "ports_item = gis.content.add(ports_item_properties)\n", |
| 2325 | + "ports_item = root_folder.add(ports_item_properties).result()\n", |
2329 | 2326 | "ports_item" |
2330 | 2327 | ] |
2331 | 2328 | }, |
|
2466 | 2463 | "execution_count": 38, |
2467 | 2464 | "metadata": {}, |
2468 | 2465 | "outputs": [ |
2469 | | - { |
2470 | | - "name": "stderr", |
2471 | | - "output_type": "stream", |
2472 | | - "text": [ |
2473 | | - "C:\\Users\\tar12555\\AppData\\Local\\ESRI\\conda\\envs\\pyapi-dev\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3553: DeprecatedWarning: create_folder is deprecated as of 2.3.0 and has be removed in 3.0.0. Use `gis.content.folders.create` instead.\n", |
2474 | | - " exec(code_obj, self.user_global_ns, self.user_ns)\n" |
2475 | | - ] |
2476 | | - }, |
2477 | 2466 | { |
2478 | 2467 | "data": { |
2479 | 2468 | "text/plain": [ |
|
2489 | 2478 | ], |
2490 | 2479 | "source": [ |
2491 | 2480 | "# create new folder\n", |
2492 | | - "gis.content.create_folder(folder='ports')" |
| 2481 | + "gis.content.folders.create_folder(folder='ports')" |
2493 | 2482 | ] |
2494 | 2483 | }, |
2495 | 2484 | { |
|
2552 | 2541 | "execution_count": 41, |
2553 | 2542 | "metadata": {}, |
2554 | 2543 | "outputs": [ |
2555 | | - { |
2556 | | - "name": "stderr", |
2557 | | - "output_type": "stream", |
2558 | | - "text": [ |
2559 | | - "C:\\Users\\tar12555\\AppData\\Local\\ESRI\\conda\\envs\\pyapi-dev\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3553: DeprecatedWarning: delete_folder is deprecated as of 2.3.0 and has be removed in 3.0.0. Use `Folder.delete()` instead.\n", |
2560 | | - " exec(code_obj, self.user_global_ns, self.user_ns)\n" |
2561 | | - ] |
2562 | | - }, |
2563 | 2544 | { |
2564 | 2545 | "data": { |
2565 | 2546 | "text/plain": [ |
|
2572 | 2553 | } |
2573 | 2554 | ], |
2574 | 2555 | "source": [ |
2575 | | - "gis.content.delete_folder(folder='ports')" |
| 2556 | + "gis.content.folders.delete_folder(folder='ports')" |
2576 | 2557 | ] |
2577 | 2558 | }, |
2578 | 2559 | { |
|
2601 | 2582 | "name": "python", |
2602 | 2583 | "nbconvert_exporter": "python", |
2603 | 2584 | "pygments_lexer": "ipython3", |
2604 | | - "version": "3.9.16" |
| 2585 | + "version": "3.11.0" |
2605 | 2586 | }, |
2606 | 2587 | "toc": { |
2607 | 2588 | "base_numbering": 1, |
|
2647 | 2628 | } |
2648 | 2629 | }, |
2649 | 2630 | "nbformat": 4, |
2650 | | - "nbformat_minor": 1 |
| 2631 | + "nbformat_minor": 4 |
2651 | 2632 | } |
0 commit comments