Created
June 10, 2013 20:17
-
-
Save oevans/5751899 to your computer and use it in GitHub Desktop.
Step 2 - Get attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, urllib, urllib2, simplejson as json | |
cwd = os.getcwd() | |
### Generate Token ### | |
gtUrl = 'https://www.arcgis.com/sharing/rest/generateToken' | |
gtValues = {'username' : 'username', | |
'password' : 'password', | |
'referer' : 'http://www.arcgis.com', | |
'f' : 'json' } | |
gtData = urllib.urlencode(gtValues) | |
gtRequest = urllib2.Request(gtUrl, gtData) | |
gtResponse = urllib2.urlopen(gtRequest) | |
gtJson = json.load(gtResponse) | |
token = gtJson['token'] | |
### Get Attachment ### | |
with open('damageassessmentservice.json') as data_file: | |
data = json.load(data_file) | |
for x in data['layers'][0]['attachments']: | |
gaUrl = x['url'] | |
gaFolder = cwd + '\\photos\\' + x['parentGlobalId'] | |
if not os.path.exists(gaFolder): | |
os.makedirs(gaFolder) | |
gaName = x['name'] | |
gaValues = {'token' : token } | |
gaData = urllib.urlencode(gaValues) | |
urllib.urlretrieve(url=gaUrl + '/' + gaName, filename=os.path.join(gaFolder, gaName),data=gaData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment