Poznáváte to?<\/P>
<\/P>
Použijeme ArcGIS API pro Python s groups.search()<\/STRONG> a users.search()<\/STRONG>, abychom získali přehled o naší organizaci. Dále sestavíme matici - uživatelé podél osy y a skupiny podél osy x<\/EM> - s 1 nebo 0 pro označení, zda je uživatel členem skupiny nebo ne. Tato matice je zapsána do CSV souboru.<\/P><\/P>A pak by měl šéf být schopen importovat tento CSV do barevné a přehledné tabulky. S nebo bez malé pomoci.<\/P><\/P>Funguje vám níže uvedený skript? Stačí "like" nebo "share", pokud ano. A pokud chcete, můžete si otevřít svůj Jupyter Notebook a vyzkoušet ho řádek po řádku.<\/P><\/P>## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>## Informace o správě ArcGIS Online<\/SPAN>## Skript: agol_group_membership.py<\/SPAN>## Cíl: vytvořit přehled členství ve skupinách ve vaší organizaci ArcGIS Online<\/SPAN>## Autor: Egge-Jan Polle - Tensing GIS Consultancy<\/SPAN>## Datum: 3. srpna 2018<\/SPAN>## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>#<\/SPAN># Tento skript by měl být spuštěn v konkrétním prostředí ArcGIS/Python pomocí níže uvedeného dávkového souboru<\/SPAN># (Tento dávkový soubor je součástí instalace ArcGIS Pro)<\/SPAN># "C:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat" agol_group_membership.py<\/SPAN>#<\/SPAN>import<\/SPAN> csv, <\/SPAN>os, <\/SPAN>sysfrom<\/SPAN> arcgis.gis import<\/SPAN> GISfrom<\/SPAN> provide_credentials import<\/SPAN> provide_credentialsprint<\/SPAN>(print<\/SPAN>(<'Skript, který běží: ' + __file__>)print<\/SPAN>(<'Nejprve se musíte přihlásit do ArcGIS Online'>)# Přihlášení<\/SPAN>username, password = provide_credentials()my_agol = GIS("https:\/\/www.arcgis.com", username, password)print ("Start: " + datetime.datetime.today().strftime('%c'))## Získat všechny skupiny<\/SPAN>my_groups = my_agol.groups.search()## Volitelně: podívat se na všechny skupiny<\/SPAN>#my_groups## Volitelně: spočítat počet skupin<\/SPAN>#len(my_groups)## Získat všechny uživatele<\/SPAN>my_users = my_agol.users.search(max_users = 350) # Výchozí hodnota max_users = 100, takže ji zvyšte, pokud máte více## Volitelně: podívat se na všechny uživatele<\/SPAN>#my_users## Volitelně: spočítat počet uživatelů<\/SPAN>#len(my_users)## Vytvořit seznam všech názvů skupin<\/SPAN>my_group_titles = []for my_group in my_groups: my_group_titles.append(my_group.title)## Vytvořit seznam názvů polí<\/SPAN>fieldnames = []fieldnames = ['USERNAME','EMAIL']for title in my_group_titles: fieldnames.append(title)## Volitelně: podívat se na názvy polí<\/SPAN>#fieldnames## Vytvořit CSV soubor s maticí skupin a jejich členů<\/SPAN>today = datetime.datetime.today().strftime('%Y%m%d')fname = 'AGOL_Group_Membership' + today + '.csv'try: os.remove(fname)except OSError: passoutfile = open(fname, 'a')writer = csv.DictWriter(outfile, delimiter=';', lineterminator='\n', fieldnames=fieldnames)writer.writeheader()## Pro každého uživatele přidat celé jméno a email a pro každou skupinu 1 nebo 0 podle členství ve skupině<\/SPAN>for user in my_users: membership = [] try: thisUser = {} thisUser['USERNAME'] = user.fullName thisUser['EMAIL'] = user.emailtry: # Členství ve skupině mimo organizaci vyvolá chybu ("Nemáte oprávnění k přístupu k tomuto zdroji nebo provedení této operace.")for group in user.groups: membership.append(group.title)except:passfor title in my_group_titles:if title in membership: thisUser[title] = 1else: thisUser[title] = 0except:print("UPOZORNĚNÍ: nelze získat žádné informace o uživateli "+user.fullName+".")pass writer.writerow(thisUser)outfile.close()print ("Hotovo: "+datetime.datetime.today().strftime('%c'))print()print('===================')print('CSV soubor lze nalézt zde:' </ span >)print </ span >(os.</ span >path.</ span >abspath(fname)</ span >)print </ span >(<'string token'> '===================' </ span >)< span class ="line-numbers-rows">< span >< < EMOJI_0 > >< / span >< span >< < EMOJI_1 > >< / span >< span >< < EMOJI_2 > >< / span >< span >< < EMOJI_3 > >< / span >< span >< < EMOJI_4 > >< / span >< span >< < EMOJI_5 > >< / span >< span >< < EMOJI_6 > >< / span >< span >< < EMOJI_7 > >< / span >< span >< < EMOJI_8 > >< / span >< span >< < EMOJI_9 > >< / span >< span >< < EMOJI_10 > >< / span >< span >< < EMOJI_11 > >< / span >< span >< < EMOJI_12 > >< / span >< span >< < EMOJI_13 > >< / span >< span >< < EMOJI_14 > >< / span >< span >< < EMOJI_15 > >< / span >< span >< < EMOJI_16 > >< / span >< span >< < EMOJI_17 > >< / span >< span >< < EMOJI_18 > >< / span >< span >< < EMOJI_19 > >< / span >< span >< < EMOJI_20 > >< / span >< span >< < EMOJI_21 > >< / span >< span >< < EMOJI_22 > >< / span >< span >< < EMOJI_23 > >< / span >< span >< < EMOJI_24 > >< / span >< span >< < EMOJI_25 > >< / span >< span >< < EMOJI_26 > >< / span /><<EM OJ I _50>> </ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an >
## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>## Informace o správě ArcGIS Online<\/SPAN>## Skript: agol_group_membership.py<\/SPAN>## Cíl: vytvořit přehled členství ve skupinách ve vaší organizaci ArcGIS Online<\/SPAN>## Autor: Egge-Jan Polle - Tensing GIS Consultancy<\/SPAN>## Datum: 3. srpna 2018<\/SPAN>## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>#<\/SPAN># Tento skript by měl být spuštěn v konkrétním prostředí ArcGIS/Python pomocí níže uvedeného dávkového souboru<\/SPAN># (Tento dávkový soubor je součástí instalace ArcGIS Pro)<\/SPAN># "C:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat" agol_group_membership.py<\/SPAN>#<\/SPAN>import<\/SPAN> csv, <\/SPAN>os, <\/SPAN>sysfrom<\/SPAN> arcgis.gis import<\/SPAN> GISfrom<\/SPAN> provide_credentials import<\/SPAN> provide_credentialsprint<\/SPAN>(print<\/SPAN>(<'Skript, který běží: ' + __file__>)print<\/SPAN>(<'Nejprve se musíte přihlásit do ArcGIS Online'>)# Přihlášení<\/SPAN>username, password = provide_credentials()my_agol = GIS("https:\/\/www.arcgis.com", username, password)print ("Start: " + datetime.datetime.today().strftime('%c'))## Získat všechny skupiny<\/SPAN>my_groups = my_agol.groups.search()## Volitelně: podívat se na všechny skupiny<\/SPAN>#my_groups## Volitelně: spočítat počet skupin<\/SPAN>#len(my_groups)## Získat všechny uživatele<\/SPAN>my_users = my_agol.users.search(max_users = 350) # Výchozí hodnota max_users = 100, takže ji zvyšte, pokud máte více## Volitelně: podívat se na všechny uživatele<\/SPAN>#my_users## Volitelně: spočítat počet uživatelů<\/SPAN>#len(my_users)## Vytvořit seznam všech názvů skupin<\/SPAN>my_group_titles = []for my_group in my_groups: my_group_titles.append(my_group.title)## Vytvořit seznam názvů polí<\/SPAN>fieldnames = []fieldnames = ['USERNAME','EMAIL']for title in my_group_titles: fieldnames.append(title)## Volitelně: podívat se na názvy polí<\/SPAN>#fieldnames## Vytvořit CSV soubor s maticí skupin a jejich členů<\/SPAN>today = datetime.datetime.today().strftime('%Y%m%d')fname = 'AGOL_Group_Membership' + today + '.csv'try: os.remove(fname)except OSError: passoutfile = open(fname, 'a')writer = csv.DictWriter(outfile, delimiter=';', lineterminator='\n', fieldnames=fieldnames)writer.writeheader()## Pro každého uživatele přidat celé jméno a email a pro každou skupinu 1 nebo 0 podle členství ve skupině<\/SPAN>for user in my_users: membership = [] try: thisUser = {} thisUser['USERNAME'] = user.fullName thisUser['EMAIL'] = user.emailtry: # Členství ve skupině mimo organizaci vyvolá chybu ("Nemáte oprávnění k přístupu k tomuto zdroji nebo provedení této operace.")for group in user.groups: membership.append(group.title)except:passfor title in my_group_titles:if title in membership: thisUser[title] = 1else: thisUser[title] = 0except:print("UPOZORNĚNÍ: nelze získat žádné informace o uživateli "+user.fullName+".")pass writer.writerow(thisUser)outfile.close()print ("Hotovo: "+datetime.datetime.today().strftime('%c'))print()print('===================')print('CSV soubor lze nalézt zde:' </ span >)print </ span >(os.</ span >path.</ span >abspath(fname)</ span >)print </ span >(<'string token'> '===================' </ span >)< span class ="line-numbers-rows">< span >< < EMOJI_0 > >< / span >< span >< < EMOJI_1 > >< / span >< span >< < EMOJI_2 > >< / span >< span >< < EMOJI_3 > >< / span >< span >< < EMOJI_4 > >< / span >< span >< < EMOJI_5 > >< / span >< span >< < EMOJI_6 > >< / span >< span >< < EMOJI_7 > >< / span >< span >< < EMOJI_8 > >< / span >< span >< < EMOJI_9 > >< / span >< span >< < EMOJI_10 > >< / span >< span >< < EMOJI_11 > >< / span >< span >< < EMOJI_12 > >< / span >< span >< < EMOJI_13 > >< / span >< span >< < EMOJI_14 > >< / span >< span >< < EMOJI_15 > >< / span >< span >< < EMOJI_16 > >< / span >< span >< < EMOJI_17 > >< / span >< span >< < EMOJI_18 > >< / span >< span >< < EMOJI_19 > >< / span >< span >< < EMOJI_20 > >< / span >< span >< < EMOJI_21 > >< / span >< span >< < EMOJI_22 > >< / span >< span >< < EMOJI_23 > >< / span >< span >< < EMOJI_24 > >< / span >< span >< < EMOJI_25 > >< / span >< span >< < EMOJI_26 > >< / span /><<EM OJ I _50>> </ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an ></ sp an >
Forgive my ignorance but where in the world would
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>os<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>path<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>abspath<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fname<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
be if I ran this on and Enterprise Notebook?
I ran this with no errors and it said:
=================== The CSV file can be found here: /arcgis/AGOL_Group_Membership20200416.csv =================== But I cannot find this file
Hi Jeff Timm,
Has the file not just been created in the same folder where the Python script resides?
BR,
Egge-Jan
Egge-Jan Pollé, this seems extremely useful, and I really appreciate you sharing! This is the type of more advanced GIS work (utilizing the API's) that I want to get in to, but for someone who is a complete newbie, I'm a bit unclear where to start. I've written/modified scripts to use in geoprocessing, but never involving multiple python files or interacting with my Organization account. Do you think you could go into a bit more detail how to approach this? (also, does this script work with both AGOL and Enterprise accounts?)
I created the JSON file and two separate .PY scripts from the code you provided, all in the same folder. Then I added the "agol_group_membership.py" script to a toolbox in ArcGIS Pro and attempted to run the tool. This is the error message I got:
Obviously I'm just not understanding how to set it up correctly. I know it's a lot to ask, but if you could at least maybe share a resource that helps explain how to get started with this stuff that would be SO helpful!
Wishing you all the best,
Katherine
Hi Katherine Clark,
Please have a look at the screen capture of the DOSBox below.
Please note: It is very important to run this script in combination with the bat file mentioned to make sure you run it in the correct ArcGIS/Python environment (This batch file comes with the installation of ArcGIS Pro). Without making sure you use this correct environment the script will fail anyway...
Please let me know if this works for you.
Stay safe, stay home - have a nice weekend.
Thank you! I got it to run once I changed the credentials in the JSON to be my ArcGIS Online login rather than my Enterprise login (is there a way to make this work with Enterprise?)
Strangely, I did receive these messages about not having permissions:
However, there was a csv produced in the same folder where the scripts are stored, as expected. The only bad part....the csv has different rows for each user, but no column separations. Have you experienced this before?
Update: I was able to correct the csv file by using the "Text to Columns" tool in the Data tab of the Excel Ribbon since all the values were neatly separated by semi colons.
However, still curious if this is expected behavior for the output of the script.
Dumb question. I wanted to find documentation about this:
"gis.users.search(max_count=...)"
Where would I find it? The answer will be embarrassing, but I can't find it. I've searched the ArcGIS API for python documentation and I don't see an explanation of this property.
I was getting a list of users and did not realize there was a limit of 100 returned and was getting extremely frustrated with the results, wondering why they were incomplete. I found your post and discovered the "max_count" property, and am now wondering how I could go straight to the source and find such information more directly.
Thank you,
Randy McGregor
Easiest way to get it to get it to automatically open in Excel as a table is to change the delimiter to a comma from a semi colon. Since we can use whatever delimeters we wish the decision on what to include here is based on the needs of the client application that will be consuming the output.
Not sure if anyone answered your question regarding making it work with Enterprise.
The answer is yes it will work with any 'portal' of whether that portal is enterprise on premesis, cloud, or arcgisonline.
Just enter the details of the portal under the login comment at the top.
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># Log in</SPAN> username<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> password <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> provide_credentials<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN> my_agol <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> GIS<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;"><SPAN style="border: 0px; font-weight: inherit;"><SPAN>"</SPAN><A _jive_internal="true" href="https://community.esri.com/yourEnterprise.com/PortalWebadaptor" target="_blank">https://yourEnterprise.com/PortalWebadaptor</A></SPAN><SPAN style="border: 0px; font-weight: inherit;">"</SPAN></SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> username<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> password<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
If the variable name "my_agol" seems a bit like a mental roadblock, you can rename it throughout the script to something like "my_portal".
Egge-Jan shared a highly adaptable and fantastically useful nugget of code here that makes short work of pulling info into spreadsheets about users and groups.
If like me you want the code to work on all your portals without much modification there are a few things you can do such as automatically naming your output csv by pulling the portal name directly via implementation of "my_portal.properties.portalName" in the fname= variable.
Could anyone suggest how this could be modified to list users within the Groups, where those users are not from the same organisation? I can get it to list our organisation's users and their Group memberships, but it excludes the hundreds of users we have in those Groups within our hub community organisation.Many thanks.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Nový zde? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.