|
POST
|
I want to search a FC where 'Field1 = No' or 'Field2 = no'
... View more
11-18-2016
12:07 PM
|
0
|
0
|
3498
|
|
POST
|
would it be easier to have a Search Cursor and WHERE clause using sql_clause?
... View more
11-18-2016
12:06 PM
|
0
|
1
|
3498
|
|
POST
|
Trying to figure out what the class_field variable is in this query fc is the Feature Class Class_field is WHAT? name_field is the field value? import arcpy
fc = 'c:/base/data.gdb/roads'
class_field = 'Road Class'
name_field = 'Name'
# Create an expression with proper delimiters
expression = arcpy.AddFieldDelimiters(fc, name_field) + ' = 2'
# Create a search cursor using an SQL expression
with arcpy.da.SearchCursor(fc, [class_field, name_field],
where_clause=expression) as cursor:
for row in cursor:
# Print the name of the residential road
print(row[1])
... View more
11-18-2016
12:05 PM
|
0
|
31
|
7562
|
|
POST
|
Just brainstorming right. Looking for some sort of solution to Alert (email) individuals when my collected data meets certain criteria. If some collected feature in a MapService or SDE FC is set to Yes or No, or some other specific value I want to grab that individual record(s) and email it to a few individuals. Has anyone done this? Thanks
... View more
11-18-2016
10:41 AM
|
0
|
2
|
2002
|
|
POST
|
THANK YOU ALL SO VERY MUCH....SO VERY APPRECIATED.....Have a great thanksgiving...cheers
... View more
11-17-2016
03:56 PM
|
0
|
0
|
1793
|
|
POST
|
Golden.....got it to work....THANK YOU ALL...went with Blakes solution... """Based on these 2014 resources by Kevin Hibma (Product Engineer at Esri):
ArcGIS Server Administration Toolkit - 10.1+
http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340
AdministeringArcGISServerwithPython_DS2014
https://github.com/arcpy/AdministeringArcGISServerwithPython_DS2014
Other related information can be found in the ArcGIS Help Resources
Scripting with the ArcGIS REST API
http://resources.arcgis.com/en/help/main/10.2/0154/0154000005r1000000.htm
"""
# Required imports
import urllib
import urllib2
import json
import contextlib ## context manager to clean up resources when exiting a 'with' block
def main(): ## Entry point into the script
# Local variables
## Authentication
adminUser = r"xxxx"
adminPass = r"xxxx"
## ArcGIS Server Machine
server = "xxxxdev.xxxx.xxxx.gov"
port = "443"
## Services ("FolderName/ServiceName.ServiceType")
svc = "Test/xInspection.MapServer"
try:
# Get ArcGIS Server token
expiration = 60 ## Token timeout in minutes; default is 60 minutes.
token = getToken(adminUser, adminPass, server, port, expiration)
# Perform action on service
action = "stop" ## "start" or "stop"
jsonOuput = serviceStartStop(server, port, svc, action, token)
## Validate JSON object result
if jsonOuput['status'] == "success":
print "{} {} successful".format(action.title(), str(svc))
else:
print "Failed to {} {}".format(action, str(svc))
raise Exception(jsonOuput)
except Exception, err:
print err
# Function to generate a token from ArcGIS Server; returns token.
## http://resources.arcgis.com/en/help/arcgis-rest-api/02r3/02r3000000m5000000.htm
def getToken(adminUser, adminPass, server, port, expiration):
# Build URL
url = "https://{}:{}/arcgis/admin/generateToken?f=json".format(server, port)
print (url)
# Encode the query string
query_dict = {
'username': adminUser,
'password': adminPass,
'expiration': str(expiration), ## Token timeout in minutes; default is 60 minutes.
'client': 'requestip'
}
query_string = urllib.urlencode(query_dict)
try:
# Request the token
with contextlib.closing(urllib2.urlopen(url, query_string)) as jsonResponse:
getTokenResult = json.loads(jsonResponse.read())
## Validate result
if "token" not in getTokenResult or getTokenResult == None:
raise Exception("Failed to get token: {}".format(getTokenResult['messages']))
else:
return getTokenResult['token']
except urllib2.URLError, e:
raise Exception("Could not connect to machine {} on port {}\n{}".format(server, port, e))
# Function to start or stop a service on ArcGIS Server; returns JSON response.
## http://resources.arcgis.com/en/help/arcgis-rest-api/02r3/02r3000001s6000000.htm
def serviceStartStop(server, port, svc, action, token):
# Build URL
url = "https://{}:{}/arcgis/admin".format(server, port)
requestURL = url + "/services/{}/{}".format(svc, action)
# Encode the query string
query_dict = {
"token": token,
"f": "json"
}
query_string = urllib.urlencode(query_dict)
# Send the server request and return the JSON response
with contextlib.closing(urllib.urlopen(requestURL, query_string)) as jsonResponse:
return json.loads(jsonResponse.read())
if __name__ == '__main__':
main()
... View more
11-17-2016
03:55 PM
|
0
|
1
|
4859
|
|
POST
|
I have to install a software - to install aother software - just to stop a service...ok trying...
... View more
11-17-2016
12:55 PM
|
1
|
0
|
4860
|
|
POST
|
download "requests-2.11.1-py-none-any.whl" ? huh Installation To install Requests, simply: $ pip install requests ✨ ✨ Satisfaction, guaranteed. I am so very confused...install this. install where? install how? ugggg
... View more
11-17-2016
12:35 PM
|
1
|
2
|
4860
|
|
POST
|
Error: Traceback (most recent call last): File "C:\Users\adminjk\Desktop\PythonSync\ServerAdminToolkit\StopService.py", line 9, in <module> import requests ImportError: No module named requests >>> sys.path.append(r'\\works.co.nz\app\GISProjects\scripts\Dev\Framework\Modules') import requests requests.packages.urllib3.disable_warnings() logging.getLogger('requests.packages.urllib3').setLevel(logging.CRITICAL)
... View more
11-17-2016
12:26 PM
|
0
|
4
|
4860
|
|
POST
|
Im trying to below....BUT I only want to hit a single service.... In ArcGIS Server Manager Site:Folder X Individual Service: D Not sure if I can configure that in the ServiceList parameter which is supported to follow format: serviceList = List of services. A service must be in the <name>.<type> notation Dont know my port number or where to find it '''
This script will stop or start all selected services
==Inputs==
ServerName
Port
AdminUser
AdminPassword (sent in clear text)
Stop or Start
Service(s) (multivalue list)
'''
import urllib, urllib2, json
import arcpy
def gentoken(server, port, adminUser, adminPass, expiration=60):
#Re-usable function to get a token required for Admin changes
query_dict = {'username': adminUser,
'password': adminPass,
'expiration': str(expiration),
'client': 'requestip'}
query_string = urllib.urlencode(query_dict)
url = "http://{}:{}/arcgis/admin/generateToken".format(server, port)
#https://vafwisdev.dgif.virginia.gov/arcgis/admin
token = json.loads(urllib.urlopen(url + "?f=json", query_string).read())
if "token" not in token:
arcpy.AddError(token['messages'])
quit()
else:
return token['token']
def stopStartServices(server, port, adminUser, adminPass, stopStart, serviceList, token=None):
''' Function to stop, start or delete a service.
Requires Admin user/password, as well as server and port (necessary to construct token if one does not exist).
stopStart = Stop|Start|Delete
serviceList = List of services. A service must be in the <name>.<type> notation
If a token exists, you can pass one in for use.
'''
# Get and set the token
if token is None:
token = gentoken(server, port, adminUser, adminPass)
# Getting services from tool validation creates a semicolon delimited list that needs to be broken up
services = serviceList.split(';')
#modify the services(s)
for service in services:
service = urllib.quote(service.encode('utf8'))
op_service_url = "http://{}:{}/arcgis/admin/services/{}/{}?token={}&f=json".format(server, port, service, stopStart, token)
status = urllib2.urlopen(op_service_url, ' ').read()
if 'success' in status:
arcpy.AddMessage(str(service) + " === " + str(stopStart))
else:
arcpy.AddWarning(status)
return
if __name__ == "__main__":
# Gather inputs
server = arcpy.GetParameterAsText(0)
port = arcpy.GetParameterAsText(1)
adminUser = arcpy.GetParameterAsText(2)
adminPass = arcpy.GetParameterAsText(3)
stopStart = arcpy.GetParameter(4)
serviceList = arcpy.GetParameterAsText(5)
stopStartServices(server, port, adminUser, adminPass, stopStart, serviceList)
... View more
11-17-2016
12:14 PM
|
0
|
0
|
4860
|
|
POST
|
Was looking into the AGS Admin link...saw the below. Not sure where to download all the scripts and stuff from the Zip file too? Can I specify a single Service? Pretty confused right now..... def stopStartServices(server, port, adminUser, adminPass, stopStart, serviceList, token=None):
''' Function to stop, start or delete a service.
Requires Admin user/password, as well as server and port (necessary to construct token if one does not exist).
stopStart = Stop|Start|Delete
serviceList = List of services. A service must be in the <name>.<type> notation
If a token exists, you can pass one in for use.
'''
# Get and set the token
if token is None:
token = gentoken(server, port, adminUser, adminPass)
# modify the services(s)
for service in serviceList:
op_service_url = "http://{}:{}/arcgis/admin/services/{}/{}?token={}&f=json".format(server, port, service, stopStart, token)
status = urllib2.urlopen(op_service_url, ' ').read()
if 'success' in status:
print (str(service) + " === " + str(stopStart))
else:
print status
return
... View more
11-17-2016
11:31 AM
|
0
|
1
|
7201
|
|
POST
|
So I only need one line of code? http://server:port/arcgis/admin/services/Maps/SeattleMap.MapServer/start What about credentials etc. and the 100 lines of code in the previous posts.
... View more
11-17-2016
11:24 AM
|
0
|
8
|
7201
|
|
POST
|
NOTE: I am trying to do this from a different server from where AGS is installed. I have to stop a service to run some code on the FC in SDe. Then restart the Service. Can I call a python script on another server? Can I do this via arcpy?
... View more
11-17-2016
10:59 AM
|
0
|
0
|
7201
|
|
POST
|
Is there a way to stop and start a map/feature service in ArcGIS Server via python?
... View more
11-17-2016
10:56 AM
|
2
|
24
|
22570
|
|
POST
|
Thanks for the info....I Should have explained myself better. I am already launching this via a toolbox. I added the script and it runs fine. But I am now looking towards automation. What I would actually like to do is fire this off with as a scheduled task. I have a couple other .py files that I can do this with but this one was built to be run as a tool. Trying to see what I have to do to convert it to a script that I can set up an OS scheduled task. Default the Parameters and then launch as a scheduled task to run every night.
... View more
11-16-2016
09:45 AM
|
0
|
3
|
2215
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-20-2018 11:09 AM | |
| 1 | 09-10-2018 06:26 AM | |
| 1 | 09-15-2022 11:02 AM | |
| 1 | 05-21-2021 07:35 AM | |
| 1 | 08-09-2022 12:39 PM |
| Online Status |
Offline
|
| Date Last Visited |
09-19-2022
09:23 PM
|