This repository was archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunsd_publish10.py
More file actions
280 lines (240 loc) · 11.8 KB
/
unsd_publish10.py
File metadata and controls
280 lines (240 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
import utils_arcgis
import json
import requests
import utils
import set_release
historic_folder = 'Historic Data 2020Q1G02'
release = set_release.set_release()
global open_data_group
global open_data_group_prod
global online_username
global online_username_admin
global gis_online_connection
# Establish ArcGIS connection
online_username, gis_online_connection = utils_arcgis.connect_to_arcGIS()
print(gis_online_connection)
# open_data_group_id:
# open_data_group_stage_id = '967dbf64d680450eaf424ac4a38799ad' #Travis
open_data_group_stage_id = 'ad013d2911184063a0f0c97d252daf32' # Luis
open_data_group_prod_id = '15c1671f5fbc4a00b1a359d51ea6a546' # SDG Open Data
open_data_group_prod_id_01 = '66d8595b381440afb5e320a9265c3fe1' # UNSD_SDG01
open_data_group_prod_id_02 = '065896a584ca4ceb920fbdd3892bee05' # UNSD_SDG02
open_data_group_prod_id_03 = 'a5552356ddd04e6fb05905bf931e9e54' # UNSD_SDG03
open_data_group_prod_id_04 = 'c15ae34432ee46b49e3533668ae63d79' # UNSD_SDG04
open_data_group_prod_id_05 = '25e04240b93f498e96427bd633b98dbc' # UNSD_SDG05
open_data_group_prod_id_06 = 'e03793e08ed849be8e8b3abebf7ec983' # UNSD_SDG06
open_data_group_prod_id_07 = 'c7e2215476e14a1a84e6990934275048' # UNSD_SDG07
open_data_group_prod_id_08 = '1c8f53673a514f83bf932b1f8a1e9ec5' # UNSD_SDG08
open_data_group_prod_id_09 = '688e20ebffb74d43b40ffbf297e3cf72' # UNSD_SDG09
open_data_group_prod_id_10 = '2b3548cac5bf4cd2941d41751b45e992' # UNSD_SDG10
open_data_group_prod_id_11 = '2455ce9284e5452a855576aad64e5a75' # UNSD_SDG11
open_data_group_prod_id_12 = '713a738b9851495aba305483fba820ca' # UNSD_SDG12
open_data_group_prod_id_13 = 'a334f601cbce43e4b47b0de8aa1a5b38' # UNSD_SDG13
open_data_group_prod_id_14 = 'b3cc3fd1f58e46df8aaaa9616186f7c7' # UNSD_SDG14
open_data_group_prod_id_15 = '157221a102d3405eb15430aff5204ad8' # UNSD_SDG15
open_data_group_prod_id_16 = '4452219ecc1c4573a4384b6b05a9b5b5' # UNSD_SDG16
open_data_group_prod_id_17 = 'dd0676a1809b40309c1302e9ba64bd89' # UNSD_SDG17
online_username_admin = 'unstats_admin'
print(online_username_admin)
print(online_username)
# ----
open_data_group_prod = gis_online_connection.groups.get(
open_data_group_prod_id)
# ----
open_data_group_prod_01 = gis_online_connection.groups.get(
open_data_group_prod_id_01)
open_data_group_prod_02 = gis_online_connection.groups.get(
open_data_group_prod_id_02)
open_data_group_prod_03 = gis_online_connection.groups.get(
open_data_group_prod_id_03)
open_data_group_prod_04 = gis_online_connection.groups.get(
open_data_group_prod_id_04)
open_data_group_prod_05 = gis_online_connection.groups.get(
open_data_group_prod_id_05)
open_data_group_prod_06 = gis_online_connection.groups.get(
open_data_group_prod_id_06)
open_data_group_prod_07 = gis_online_connection.groups.get(
open_data_group_prod_id_07)
open_data_group_prod_08 = gis_online_connection.groups.get(
open_data_group_prod_id_08)
open_data_group_prod_09 = gis_online_connection.groups.get(
open_data_group_prod_id_09)
open_data_group_prod_10 = gis_online_connection.groups.get(
open_data_group_prod_id_10)
open_data_group_prod_11 = gis_online_connection.groups.get(
open_data_group_prod_id_11)
open_data_group_prod_12 = gis_online_connection.groups.get(
open_data_group_prod_id_12)
open_data_group_prod_13 = gis_online_connection.groups.get(
open_data_group_prod_id_13)
open_data_group_prod_14 = gis_online_connection.groups.get(
open_data_group_prod_id_14)
open_data_group_prod_15 = gis_online_connection.groups.get(
open_data_group_prod_id_15)
open_data_group_prod_16 = gis_online_connection.groups.get(
open_data_group_prod_id_16)
open_data_group_prod_17 = gis_online_connection.groups.get(
open_data_group_prod_id_17)
# --------------------
# Production Site Changes
# Search all the Items in Production Open Data Group
user = gis_online_connection.users.get(online_username)
admin_user = gis_online_connection.users.get(online_username_admin)
print(user)
print(admin_user)
sdg_meta = utils.open_json('data/external/metadata_' + release + '.json')
for g in sdg_meta:
# if g['code'] not in ['1']:
# continue
goal_code = g['code']
user_items = admin_user.items(
folder='Open Data - SDG '+goal_code.zfill(2), max_items=800)
for item in user_items:
# Move these items into Archive folder under the Admin User
print('Moving ' + item.title + ' to archive folder')
item.move(folder="Historic Data 2019Q3G01",
owner=online_username_admin)
# Unshare the Items from Open Data Group (Production)
print('unsharing item ' + item.title + " from the open data group")
item.unshare(open_data_group_prod["id"])
if goal_code == '1':
item.unshare(open_data_group_prod_01["id"])
elif goal_code == '2':
item.unshare(open_data_group_prod_02["id"])
elif goal_code == '3':
item.unshare(open_data_group_prod_03["id"])
elif goal_code == '4':
item.unshare(open_data_group_prod_04["id"])
elif goal_code == '5':
item.unshare(open_data_group_prod_05["id"])
elif goal_code == '6':
item.unshare(open_data_group_prod_06["id"])
elif goal_code == '7':
item.unshare(open_data_group_prod_07["id"])
elif goal_code == '8':
item.unshare(open_data_group_prod_08["id"])
elif goal_code == '9':
item.unshare(open_data_group_prod_09["id"])
elif goal_code == '10':
item.unshare(open_data_group_prod_10["id"])
elif goal_code == '11':
item.unshare(open_data_group_prod_11["id"])
elif goal_code == '12':
item.unshare(open_data_group_prod_12["id"])
elif goal_code == '13':
item.unshare(open_data_group_prod_13["id"])
elif goal_code == '14':
item.unshare(open_data_group_prod_14["id"])
elif goal_code == '15':
item.unshare(open_data_group_prod_15["id"])
elif goal_code == '16':
item.unshare(open_data_group_prod_16["id"])
elif goal_code == '17':
item.unshare(open_data_group_prod_17["id"])
# Update Tags (Remove Current add Historic)
item_properties = {}
item_properties["tags"] = item.tags
if 'Current' in item_properties["tags"]:
item_properties["tags"] = item_properties["tags"].remove(
'Current')
item_properties["tags"].append('Historic')
item.update(item_properties=item_properties)
# Mark this item as depracated
utils_arcgis.set_content_status(
gis_online_connection, item, authoratative=False)
# -----------------------------------------------------------
# Staging Site Changes
# Get all the Items in the Open Data Folder
# -----------------------------------------------------------
user_items = user.items(
folder='Open Data SDG' + goal_code.zfill(2), max_items=800)
# Move all the CSV Files to the Open Data Folder of the Admin User
# This will also move the Feature Service Layer!!!!
for item in user_items:
if item.type == 'CSV':
# Assign Item to the Admin User
print('reassigning item ' + item.title + ' from ' +
online_username + ' to ' + online_username_admin)
item.reassign_to(online_username_admin,
'Open Data - SDG ' + goal_code.zfill(2))
# -----------------------------------------------------------
# Update the Items in the Open Data Folder of the Admin User
# -----------------------------------------------------------
user_items = admin_user.items(
folder='Open Data - SDG ' + goal_code.zfill(2), max_items=800)
# Update Sharing to Public, Share with Open Data Group
for item in user_items:
if item.type != 'CSV':
print('updating sharing for item ' + item.title)
if goal_code == '1':
item.share(
everyone=True, org=True, groups=open_data_group_prod_01["id"], allow_members_to_edit=False)
elif goal_code == '2':
item.share(
everyone=True, org=True, groups=open_data_group_prod_02["id"], allow_members_to_edit=False)
elif goal_code == '3':
item.share(
everyone=True, org=True, groups=open_data_group_prod_03["id"], allow_members_to_edit=False)
elif goal_code == '4':
item.share(
everyone=True, org=True, groups=open_data_group_prod_04["id"], allow_members_to_edit=False)
elif goal_code == '5':
item.share(
everyone=True, org=True, groups=open_data_group_prod_05["id"], allow_members_to_edit=False)
elif goal_code == '6':
item.share(
everyone=True, org=True, groups=open_data_group_prod_06["id"], allow_members_to_edit=False)
elif goal_code == '7':
item.share(
everyone=True, org=True, groups=open_data_group_prod_07["id"], allow_members_to_edit=False)
elif goal_code == '8':
item.share(
everyone=True, org=True, groups=open_data_group_prod_08["id"], allow_members_to_edit=False)
elif goal_code == '9':
item.share(
everyone=True, org=True, groups=open_data_group_prod_09["id"], allow_members_to_edit=False)
elif goal_code == '10':
item.share(
everyone=True, org=True, groups=open_data_group_prod_10["id"], allow_members_to_edit=False)
elif goal_code == '11':
item.share(
everyone=True, org=True, groups=open_data_group_prod_11["id"], allow_members_to_edit=False)
elif goal_code == '12':
item.share(
everyone=True, org=True, groups=open_data_group_prod_12["id"], allow_members_to_edit=False)
elif goal_code == '13':
item.share(
everyone=True, org=True, groups=open_data_group_prod_13["id"], allow_members_to_edit=False)
elif goal_code == '14':
item.share(
everyone=True, org=True, groups=open_data_group_prod_14["id"], allow_members_to_edit=False)
elif goal_code == '15':
item.share(
everyone=True, org=True, groups=open_data_group_prod_15["id"], allow_members_to_edit=False)
elif goal_code == '16':
item.share(
everyone=True, org=True, groups=open_data_group_prod_16["id"], allow_members_to_edit=False)
elif goal_code == '17':
item.share(
everyone=True, org=True, groups=open_data_group_prod_17["id"], allow_members_to_edit=False)
# Disable Editing on the Feature Service
print('disable editing for ' + item.title)
item_flc = FeatureLayerCollection.fromitem(item)
update_dict2 = {"capabilities": "Query, Extract"}
item_flc.manager.update_definition(update_dict2)
# Unshare from Staging Group
#print('unsharing item ' + item.title + " from the staging group")
# item.unshare(open_data_group["id"])
print('enabling delete protection for: ' + item.title)
item.protect(enable=True)
# Tag as Current
print('updating item properties for ' + item.title)
item_properties = dict()
item_properties["tags"] = item.tags.append('Current')
item.update(item_properties=item_properties)
# Mark this item as authoratative
print('marking item ' + item.title + " as authortative")
utils_arcgis.set_content_status(
gis_online_connection, item, authoratative=True)