I'm using the arcgis api for Python to generate a report that shows all of our content on arcgis online. We are particularly interested in having the usage stats on here. Its a pretty basic script tbh.
mygis = GIS("https://mygis.maps.arcgis.com","Username", "Password", **exp_time )
content = mygis.content.search(query="", sort_field="title", sort_order="asc", max_items=100)
def main():
outpath = Path(r"C:\\GIS\\output\\agol\\testagolreport.csv")
content_run = content
with outpath.open("a", newline='') as outfile:
# Loop through content items and write to CSV, etc.Because we have so much content I am unable to run my script for all the content at once. I have to break up my script into chunks, so I was thinking something like [A*,B*,C*,D*], [E*,F*,G*,H*], etc.
But the way AGOL / Portal use Elasticsearch, I can't search for items by doing a wildcard title search for the first letter or whatever. If you search for 'EAST*', It returns items with the word East anywhere in title, not just at the beginning.
I am guessing there is a way to solve this using list comprehension or filtering somehow. Should I get all the matching items from the initial elasticsearch query, then filter them out? I found this snippet on an older post:
searched_items=[item for item in gis. content.search(query="title: base_map", item_type="Map Service", max_items=20 if item.title=="base_map"]
Couldn't get it to work. It seems inefficient to have to do things this way. Fuzzy search queries work fine at the interface level but for generating reports its a real pain, maybe I'm missing something. Anyone figured this out and have a snippet they can share?
Thanks!