これを認識しますか?<\/P>
<\/P>
私たちはArcGIS API for Pythonを使用して、groups.search()<\/STRONG> と users.search()<\/STRONG> を使い、組織の概要を取得します。次にマトリックスを作成します - y軸にユーザー、x軸にグループを配置したもの<\/EM> - ユーザーがそのグループのメンバーであれば1、そうでなければ0を示します。このマトリックスはCSVファイルに書き込まれます。<\/P><\/P>そして上司は、このCSVをカラフルで管理しやすいスプレッドシートにインポートできるようになります。少し助けがあってもなくても。<\/P><\/P>以下のスクリプトはあなたにとって機能しますか?機能する場合は「いいね」または「共有」をしてください。もしよければ、Jupyter Notebookを開いて一行ずつ試すこともできます。<\/P><\/P>## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>## ArcGIS Online 管理情報<\/SPAN>## スクリプト: agol_group_membership.py<\/SPAN>## 目的: ArcGIS Online組織内のグループメンバーシップの概要を作成すること<\/SPAN>## 著者: Egge-Jan Polle - Tensing GIS Consultancy<\/SPAN>## 日付: 2018年8月3日<\/SPAN>## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>#<\/SPAN># このスクリプトは特定のArcGIS/Python環境内で以下のバッチファイルを使って実行する必要があります<\/SPAN># (このバッチファイルはArcGIS Proのインストール時に付属しています)<\/SPAN># "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\scripts\\propy.bat" agol_group_membership.py<\/SPAN>#<\/SPAN>import<\/SPAN> csv, os, sysfrom<\/SPAN> arcgis.gis import<\/SPAN> GISfrom<\/SPAN> provide_credentials import<\/SPAN> provide_credentialsprint('===================')print('実行中のスクリプト: ' + __file__)print('最初にArcGIS Onlineにログインしてください')# ログインusername, password = provide_credentials()my_agol = GIS("https://www.arcgis.com", username, password)print("開始: " + datetime.datetime.today().strftime('%c'))## すべてのグループを取得my_groups = my_agol.groups.search()## 必要に応じて: すべてのグループを見る#my_groups## 必要に応じて: グループ数を数える#len(my_groups)## すべてのユーザーを取得my_users = my_agol.users.search(max_users=350) # max_users のデフォルトは100なので、もっと多い場合は増やしてください## 必要に応じて: すべてのユーザーを見る#my_users## 必要に応じて: ユーザー数を数える#len(my_users)## すべてのグループタイトルのリストを作成my_group_titles = []for my_group in my_groups: my_group_titles.append(my_group.title)## フィールド名リストを作成fieldnames = []fieldnames = ['USERNAME', 'EMAIL']for title in my_group_titles: fieldnames.append(title)## 必要に応じて: フィールド名を見る#fieldnames## メンバー付きグループマトリックスのCSVファイルを作成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()## 各ユーザーについて、フルネームとメールアドレス、および各グループについてメンバーなら1、そうでなければ0を追加for user in my_users: membership = [] try: thisUser = {} thisUser['USERNAME'] = user.fullName thisUser['EMAIL'] = user.emailtry: # 組織外のグループメンバーシップはエラーを発生させます("このリソースにアクセスする権限がないか、この操作を実行する権限がありません。")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("注意:ユーザー "+user.fullName+" に関する情報を取得できません。")pass writer.writerow(thisUser)outfile.close()print ("準備完了: "+datetime.datetime.today().strftime('%c'))print()print()</ span >print </ span >< spanclass= " punctuationtoken ">( </ span >< spanclass= " stringtoken ">'CSVファイルはここにあります:' </ span >< spanclass= " punctuationtoken ">) </ span >print </ span >< spanclass= " punctuationtoken ">( </ span >os. </ span >path. </ span >abspath( </ span >fname) </ span >) </ span >print </ span >< spanclass= " punctuationtoken ">( </ span >< spanclass= " stringtoken ">'===================' </ span >< spanclass= " punctuationtoken ">) </ span >And here is the provide_credentials スクリプトは上記でAGOLにログインするために使用されます:import json, osfrom getpass import getpass # パスワードを対話的に受け取るために使用します。def provide_credentials(): file_with_credentials = 'my_credentials.json' username = '' password = '' if os.path.exists(file_with_credentials): with open(file_with_credentials) as f: data = json.load(f) username = data['username'] password = data['password'] if not username or username == 'USERNAME' or not password or password == 'PASSWORD': username = input('ユーザー名を入力してください: ') password = getpass('パスワードを入力してください(入力は表示されません): ') return username, password入力ファイル my_credentials.json: { "username":"USERNAME", "password":"PASSWORD"}楽しいコーディングを!Egge-Jan
## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>## ArcGIS Online 管理情報<\/SPAN>## スクリプト: agol_group_membership.py<\/SPAN>## 目的: ArcGIS Online組織内のグループメンバーシップの概要を作成すること<\/SPAN>## 著者: Egge-Jan Polle - Tensing GIS Consultancy<\/SPAN>## 日付: 2018年8月3日<\/SPAN>## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<\/SPAN>#<\/SPAN># このスクリプトは特定のArcGIS/Python環境内で以下のバッチファイルを使って実行する必要があります<\/SPAN># (このバッチファイルはArcGIS Proのインストール時に付属しています)<\/SPAN># "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\scripts\\propy.bat" agol_group_membership.py<\/SPAN>#<\/SPAN>import<\/SPAN> csv, os, sysfrom<\/SPAN> arcgis.gis import<\/SPAN> GISfrom<\/SPAN> provide_credentials import<\/SPAN> provide_credentialsprint('===================')print('実行中のスクリプト: ' + __file__)print('最初にArcGIS Onlineにログインしてください')# ログインusername, password = provide_credentials()my_agol = GIS("https://www.arcgis.com", username, password)print("開始: " + datetime.datetime.today().strftime('%c'))## すべてのグループを取得my_groups = my_agol.groups.search()## 必要に応じて: すべてのグループを見る#my_groups## 必要に応じて: グループ数を数える#len(my_groups)## すべてのユーザーを取得my_users = my_agol.users.search(max_users=350) # max_users のデフォルトは100なので、もっと多い場合は増やしてください## 必要に応じて: すべてのユーザーを見る#my_users## 必要に応じて: ユーザー数を数える#len(my_users)## すべてのグループタイトルのリストを作成my_group_titles = []for my_group in my_groups: my_group_titles.append(my_group.title)## フィールド名リストを作成fieldnames = []fieldnames = ['USERNAME', 'EMAIL']for title in my_group_titles: fieldnames.append(title)## 必要に応じて: フィールド名を見る#fieldnames## メンバー付きグループマトリックスのCSVファイルを作成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()## 各ユーザーについて、フルネームとメールアドレス、および各グループについてメンバーなら1、そうでなければ0を追加for user in my_users: membership = [] try: thisUser = {} thisUser['USERNAME'] = user.fullName thisUser['EMAIL'] = user.emailtry: # 組織外のグループメンバーシップはエラーを発生させます("このリソースにアクセスする権限がないか、この操作を実行する権限がありません。")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("注意:ユーザー "+user.fullName+" に関する情報を取得できません。")pass writer.writerow(thisUser)outfile.close()print ("準備完了: "+datetime.datetime.today().strftime('%c'))print()print()</ span >print </ span >< spanclass= " punctuationtoken ">( </ span >< spanclass= " stringtoken ">'CSVファイルはここにあります:' </ span >< spanclass= " punctuationtoken ">) </ span >print </ span >< spanclass= " punctuationtoken ">( </ span >os. </ span >path. </ span >abspath( </ span >fname) </ span >) </ span >print </ span >< spanclass= " punctuationtoken ">( </ span >< spanclass= " stringtoken ">'===================' </ span >< spanclass= " punctuationtoken ">) </ span >And here is the provide_credentials スクリプトは上記でAGOLにログインするために使用されます:import json, osfrom getpass import getpass # パスワードを対話的に受け取るために使用します。def provide_credentials(): file_with_credentials = 'my_credentials.json' username = '' password = '' if os.path.exists(file_with_credentials): with open(file_with_credentials) as f: data = json.load(f) username = data['username'] password = data['password'] if not username or username == 'USERNAME' or not password or password == 'PASSWORD': username = input('ユーザー名を入力してください: ') password = getpass('パスワードを入力してください(入力は表示されません): ') return username, password入力ファイル my_credentials.json: { "username":"USERNAME", "password":"PASSWORD"}楽しいコーディングを!Egge-Jan
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.
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.