Editing Hub page text using python

1127
17
05-09-2022 12:41 PM
Steve_Graham
New Contributor II

How can I edit text on an ArcGIS Hub site page? 

0 Kudos
17 Replies
Waffle_House
Occasional Contributor II
0 Kudos
Steve_Graham
New Contributor II

Yes , but I am wondering how you can edit the text on a hub page with Python.

0 Kudos
ManushiMajumdar
Esri Contributor

yes, we have an example guide that demonstrates the process of editing layout of a page to edit text.

0 Kudos
Steve_Graham
New Contributor II

Thank you, but I am wondering how you can EDIT some of the TEXT in a card on a hub page with Python. 

0 Kudos
ManushiMajumdar
Esri Contributor

you need to edit the text within the html of the particular card. Fetch the card (as demonstrated in the example notebook), edit the card to replace text as seen on the site with the text you would like instead, and then call the update_layout method with the changes.

0 Kudos
Steve_Graham
New Contributor II

Something like this?

for p in site_pages:
    if p.slug=="county-profile":
        thepage = p
thelayout=thepage.layout
thelayout.sections[0].ROWS[0].cards[0].component.settings.markdown ="the new text to display"
thepage.update_layout(thelayout)
 
I get an error 404 
Exception: Resource does not exist or is inaccessible:
0 Kudos
ManushiMajumdar
Esri Contributor

When you `print(thelayout.sections[0].ROWS[0].cards[0].component.settings.markdown)` what does it display? Overwrite the same value in the markdown variable and only replace the text string with the text string of your choice.

Also, you can only update the layout if you own the page/site OR are part of the initiative core team OR an org administrator.

0 Kudos
Steve_Graham
New Contributor II

Print returns

<h1 id='our-community'>Douglas County Profile</h1><p>The information included below provides context for the Hazard Mitigation Plan. Environmental, social, and economic characteristics of a county make it unique.&nbsp;</p><p><br></p>

I then can set it = to its original value or anything and get the error.

thelayout.sections[0].ROWS[0].cards[0].component.settings.markdown ="the new text to display"
 

I am able to edit it through the web interface hub.arcgis.com with the same user

0 Kudos
Steve_Graham
New Contributor II

Maybe you could give an example of code you have used that works?

0 Kudos