-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenterprise_tester.py
88 lines (78 loc) · 2.5 KB
/
enterprise_tester.py
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
import yaml
from PortalExporter import PortalResource
# from PortalExporter import PortalResource
#from PortalExporter import PortalSpatialResource
from PortalExporter import PortalConnector
from PortalExporter import DatabaseConnector
import os
from arcgis.gis import GIS
##############################################################################
# Setup: construct connector (for Examples 1 and 2)
##############################################################################
with open(r'Config\\auth.yml') as file:
auth = yaml.load(file, Loader=yaml.FullLoader)
portal_conn = PortalConnector(
portal_username=auth['enterprise']['username'],
portal_pw=auth['enterprise']['pw'])
elmer_conn = DatabaseConnector(
db_server='SQLserver',
database='Elmer')
elmergeo_conn = DatabaseConnector(
db_server='AWS-PROD-SQL\Sockeye',
database='ElmerGeo')
def export(config):
try:
for k in config.keys():
params = config[k]['layer_params']
title = params['title']
source = config[k]['source']
is_spatial = params['spatial_data']
if is_spatial:
db_conn = elmergeo_conn
else:
db_conn = elmer_conn
my_pub = PortalResource(
p_connector=portal_conn,
db_connector=db_conn,
params=params,
source=source
)
if is_spatial:
if source['is_simple']:
my_pub.define_spatial_source_layer(
layer_name=source['table_name'])
else:
my_pub.define_source_from_query(
sql_query=source['sql_query']
)
else:
if source['is_simple']:
my_pub.define_simple_source(
in_schema=source['schema_name'],
in_recordset_name=source['table_name'])
else:
my_pub.define_source_from_query(
sql_query=source['sql_query']
)
my_pub.export()
print("exported {}".format(title))
except Exception as e:
print('Error for layer {}'.format(title))
print(e.args[0])
raise
##############################################################################
#Example 1: export tables and/or view using define_simple_source
# Use the config info in config\config.yml
##############################################################################
# for each yaml file in folder
# run_files = os.listdir('./Config/run_files/')
# root_dir = os.getcwd()
# for f in run_files:
# os.chdir(root_dir)
# # if r'assessor_net_housing_by_' in f:
# if f in ['Household_Travel_Survey_Persons.yml']:
# print(f"exporting {f}")
# f_path = './Config/run_files/' + f
# with open(f_path) as file:
# config = yaml.load(file, Loader=yaml.FullLoader)
# export(config)