I put together this script to replicate a service based on the code I posted in the Issue 1 thread. It's just a script, so it can be run independently of the ArcGIS environment. It was written for Python 2.6, but I imagine it should work for 2.7 as well, since there are no 2.6-specific lines that look like this in there:
Hi Brian,
I put together this script to replicate a service based on the code I posted in the Issue 1 thread. It's just a script, so it can be run independently of the ArcGIS environment. It was written for Python 2.6, but I imagine it should work for 2.7 as well, since there are no 2.6-specific lines that look like this in there:
'query?where={0}&returnIdsOnly=true&' 'f=json&token={1}'
It's made to create daily backups, so it checks for a folder from the previous day, deletes it, and creates a new folder for the current day.
Feel free to post it in the repo.
import json, urllib, urllib2 import sys, os import shutil import time, datetime from datetime import date, timedelta import zipfile
today = date.today() todayString = today.strftime("%Y.%m.%d") serviceTodayString = 'WAYS_RiverbankAcquisition'+ todayString yesterday = date.today() - timedelta(1) yesterdayString = yesterday.strftime('%Y.%m.%d') serviceYesterdayString = r'G:\Dvkoord\GIS\TEMP\Tle\Scripts\WAYS_RiverbankAcquisition'+ yesterdayString
class GetToken(object): def urlopen(self, url, data=None): referer = "http://www.arcgis.com/arcgis/rest" req = urllib2.Request(url) req.add_header('Referer', referer) if data: response = urllib2.urlopen(req, data) else: response = urllib2.urlopen(req) return response
class QueryService (object): def init (self, service_query, token, service_url): self.service_url = os.path.split(service_url)[0][:-1] + "createReplica" self.token = token self.service_query = service_query
class DownloadService(GetToken): def init(self, fs, field, destination, user, pw, service_query): self.fs = fs +'/' self.field = field self.where = '1=1' self.token = self.gentoken(user, pw) self.destination = os.path.join(destination, serviceTodayString) self.service_query = service_query
def main(): service_url = 'http://services1.arcgis.com/0cr41EdkajvOA232/ArcGIS/rest/services//FeatureServer/0'
username = "username"
password = "password"
directory = r'G:\Dvkoord\GIS\TEMP\Tle\Scripts'
field_name = ''
service_query = {
"geometry": '',
"geometryType": "esriGeometryEnvelope",
"inSR": '',
"layerQueries": '',
"layers": "0, 1, 2",
"replicaName": "read_only_rep",
"returnAttachments": 'true',
"returnAttachmentsDataByUrl": 'true',
"transportType": "esriTransportTypeEmbedded",
"async": 'false',
"syncModel": "none",
"dataFormat": "filegdb",
"token": '',
"replicaOptions": '',
"f": "json"
}
run = DownloadService(service_url, field_name, directory, username, password, service_query)
run.pullService()
if name == 'main': main()