diff --git a/README.md b/README.md index 9396260..95639e7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ In order to install Python, install the bundle that comes with the Anaconda dist Execute the following command in the terminal -``` pip install -e git+https://github.com/esridc/hub-py.git#egg=arcgishub ``` +``` pip install -e git+https://github.com/esri/hub-py.git#egg=arcgishub ``` Once installed, test it by launching an instance of Jupyter Notebook and importing the package @@ -22,7 +22,7 @@ Once installed, test it by launching an instance of Jupyter Notebook and importi Execute the following command in the terminal -``` pip install -e git+https://github.com/esridc/hub-py.git#egg=arcgishub ``` +``` pip install -e git+https://github.com/esri/hub-py.git#egg=arcgishub ``` Once installed, test it by launching an instance of Jupyter Notebook and importing the package @@ -47,15 +47,15 @@ initiatives = myHub.initiatives.search() print(initiatives) ``` -fetches a list containing all the initiatives within this Hub. Click [here](https://github.com/esridc/hub-py/wiki) for more information and API reference about the functionality supported. +fetches a list containing all the initiatives within this Hub. Click [here](https://github.com/esri/hub-py/wiki) for more information and API reference about the functionality supported. ### User Guides -Example notebooks for using this API to work with your Hub are provided in the [examples](https://github.com/esridc/hub-py/tree/master/examples) directory. +Example notebooks for using this API to work with your Hub are provided in the [examples](https://github.com/esri/hub-py/tree/master/examples) directory. -If you are working with `arcgishub` >=v2.1.0, you will find the above examples and functionality supported in this API under the [For arcgishub](https://github.com/esridc/hub-py/tree/master/examples/For%20arcgishub) folder. +If you are working with `arcgishub` >=v2.1.0, you will find the above examples and functionality supported in this API under the [For arcgishub](https://github.com/esri/hub-py/tree/master/examples/For%20arcgishub) folder. -Older versions of this API can also be found in the [ArcGIS API for Python](https://developers.arcgis.com/python/). You can find user guides to access Hub using it, under the [For ArcGIS API for Python](https://github.com/esridc/hub-py/tree/master/examples/For%20ArcGIS%20API%20for%20Python) subdirectory. +Older versions of this API can also be found in the [ArcGIS API for Python](https://developers.arcgis.com/python/). You can find user guides to access Hub using it, under the [For ArcGIS API for Python](https://github.com/esri/hub-py/tree/master/examples/For%20ArcGIS%20API%20for%20Python) subdirectory. -We encourage you to provide feedback/issues in implementation, under GitHub [issues](https://github.com/esridc/hub-py/issues) for this repo. +We encourage you to provide feedback/issues in implementation, under GitHub [issues](https://github.com/esri/hub-py/issues) for this repo. diff --git a/arcgishub/hub.py b/arcgishub/hub.py index 8ded03b..4a0f645 100644 --- a/arcgishub/hub.py +++ b/arcgishub/hub.py @@ -2,7 +2,7 @@ from arcgis.features import FeatureLayer from arcgis.geocoding import geocode from arcgis._impl.common._mixins import PropertyMap -from arcgishub.sites import SiteManager, PageManager +from arcgishub.sites import Site, SiteManager, Page, PageManager from arcgis.features.enrich_data import enrich_layer from datetime import datetime from collections import OrderedDict @@ -143,7 +143,7 @@ def community_org_url(self): except: print("Hub does not exist or is inaccessible.") raise - + @_lazy_property def initiatives(self): """ @@ -172,6 +172,76 @@ def pages(self): """ return PageManager(self.gis) + def search(self, title=None, owner=None, created=None, modified=None, tags=None, scope=None): + """ + Provides search functionality within the organization's hub. Results will be organized + as either Initiatives + + =============== ==================================================================== + **Argument** **Description** + --------------- -------------------------------------------------------------------- + title Optional string. Return hub items with provided string in title. + --------------- -------------------------------------------------------------------- + owner Optional string. Return hub items owned by a username. + --------------- -------------------------------------------------------------------- + created Optional string. Date the hub item was created. + Shown in milliseconds since UNIX epoch. + --------------- -------------------------------------------------------------------- + modified Optional string. Date the hub item was last modified. + Shown in milliseconds since UNIX epoch + --------------- -------------------------------------------------------------------- + tags Optional string. User-defined tags that describe the hub item. + --------------- -------------------------------------------------------------------- + scope Optional string. Defines the scope of search. + Valid values are 'official', 'community' or 'all'. + =============== ==================================================================== + """ + resultList = [] + #Build search query + query = 'typekeywords:hub' + if title!=None: + query += ' AND title:'+title + if owner!=None: + query += ' AND owner:'+owner + if created!=None: + query += ' AND created:'+created + if modified!=None: + query += ' AND modified:'+modified + if tags!=None: + query += ' AND tags:'+tags + + #Apply org scope and search + if scope is None or self.gis.url=='https://www.arcgis.com': + items = self.gis.content.search(query=query, item_type='Hub *', max_items=5000) + elif scope.lower()=='official': + query += ' AND access:public' + _gis = GIS(self.enterprise_org_url) + items = _gis.content.search(query=query, item_type='Hub *', max_items=5000) + elif scope.lower()=='community': + query += ' AND access:public' + _gis = GIS(self.community_org_url) + items = _gis.content.search(query=query, item_type='Hub *', max_items=5000) + elif scope.lower()=='all': + items = self.gis.content.search(query=query, item_type='Hub *', outside_org=True, max_items=5000) + else: + raise Exception("Invalid value for scope") + + for item in items: + if "hubInitiative" in item.typeKeywords: + resultList.append(Initiative(self, item)) + elif "hubSite" in item.typeKeywords: + resultList.append(Site(self.gis, item)) + elif "hubPage" in item.typeKeywords: + resultList.append(Page(self.gis, item)) + elif "hubInitiativeTemplate" in item.typeKeywords: + # leaving room for an InitiativeTemplate object. + # In the mean time, treat it as an item + resultList.append(item) + else: + # not sure what this is. Will just send back the item + resultList.append(item) + return resultList + class Initiative(OrderedDict): """ Represents an initiative within a Hub. An Initiative supports diff --git a/arcgishub/sites.py b/arcgishub/sites.py index 9633810..6abbd60 100644 --- a/arcgishub/sites.py +++ b/arcgishub/sites.py @@ -763,6 +763,15 @@ def slug(self): Returns the page slug """ return self.title.replace(' ', '-').lower() + + @property + def layout(self): + """ + Return layout of a page + """ + if self.definition is None: + return None + return InsensitiveDict(self.definition['values']['layout']) def update(self, page_properties=None, slug=None, data=None, thumbnail=None, metadata=None): """ Updates the page. @@ -797,6 +806,30 @@ def update(self, page_properties=None, slug=None, data=None, thumbnail=None, met _page_data[key] = value return self.item.update(_page_data, data, thumbnail, metadata) + def update_layout(self, layout): + """ Updates the layout of the page. + ===================== ==================================================================== + **Argument** **Description** + --------------------- -------------------------------------------------------------------- + layout Required dictionary. The new layout dictionary to update to the page. + ===================== ==================================================================== + :return: + A boolean indicating success (True) or failure (False). + .. code-block:: python + USAGE EXAMPLE: Update a page successfully + page1 = myHub.pages.get('itemId12345') + page_layout = page1.layout + page_layout.sections[0].rows[0].cards.pop(0) + page1.update_layout(layout = page_layout) + >> True + """ + if self.definition is None: + # no page definition, for some reason + return False + self.definition['values']['layout'] = layout._json() + self.definition['values']['updatedBy'] = self._gis.users.me.username + return self.item.update(item_properties={'text': self.definition}) + def delete(self): """ Deletes the page. If unable to delete, raises a RuntimeException. diff --git a/examples/For arcgishub/Accessing events and plotting them on a map.ipynb b/examples/For arcgishub/Accessing events and plotting them on a map.ipynb index 1bd3e39..c2b383d 100644 --- a/examples/For arcgishub/Accessing events and plotting them on a map.ipynb +++ b/examples/For arcgishub/Accessing events and plotting them on a map.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Accessign events in your Hub and plotting them on a map" + "### Accessing events in your Hub and plotting them on a map" ] }, { @@ -319,4 +319,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file