-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdates_to_ContractorDomain.py
More file actions
78 lines (64 loc) · 2.27 KB
/
Updates_to_ContractorDomain.py
File metadata and controls
78 lines (64 loc) · 2.27 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
import arcpy # not installed on local, but is on Grapery VM
import pandas as pd
from arcgis.gis import GIS
from time import sleep
import sys
from copy import deepcopy
def main():
uname = ""
pwd = ""
server_name = ''
instance = ''
database = ''
dbuser = ''
dbpass = ''
db_path = ''
db_sde = ''
table_name = ''
field_name = ''
try:
gis = GIS("", uname, pwd)
print("Logged in as " + gis.properties.user.username +
' to ' + gis.properties.name + '.')
except Exception:
print('Failed to login. Check credentials and network connection and try again.')
try:
egdb_conn = arcpy.ArcSDESQLExecute(
server_name, instance, database, dbuser, dbpass)
print("Successfully connected to server.")
print('')
except Exception as err:
print(err)
# Get Contractor table, Internal Assignment Item
# pull in Internal Assignment layer
Job_IntAssgn_prod = gis.content.search(
'Job_IntAssgn')[0] # production dataset
#call the needed feature layers
contractor = Job_IntAssgn_prod.tables[0]
NewDmnCnt = len(contractor.query(where="DomainXfer=0"))
if NewDmnCnt != 0:
print(f'{NewDmnCnt} domain items to be added.')
dfContractorDmn = contractor.query()
dbDmn = dfContractorDmn.sdf.drop_duplicates(subset=['contractor_name'])
code = dbDmn.columns[0]
description = dbDmn.columns[0]
arcpy.TableToDomain_management(dbDmn, code,
description, db_path + db_sde,
'Contractor', "List of FLC's", 'REPLACE')
print('Items added. Updating web service...')
sleep(2)
features_to_be_edited = []
for indx, row in dfContractorDmn.sdf.iterrows():
new_feature = deepcopy(dfContractorDmn.features[indx])
new_feature.attributes['DomainXfer'] = 1
features_to_be_edited.append(new_feature)
contractor.edit_features(updates=features_to_be_edited)
print('Successfully updated domain!')
print('Terminating...')
sleep(2)
else:
print('No new domain updates')
print('Terminating...')
sleep(2)
if __name__ == '__main__':
main()