Skip to content

Instantly share code, notes, and snippets.

@Adizlois
Last active May 5, 2017 09:08
Show Gist options
  • Save Adizlois/c1e4d54b0d50550c6c2bfd4f0478aaf0 to your computer and use it in GitHub Desktop.
Save Adizlois/c1e4d54b0d50550c6c2bfd4f0478aaf0 to your computer and use it in GitHub Desktop.
XML extraction example (including pictures downloading) for an epicollect project
#!/usr/bin/env python
import urllib2
import urllib
import xml.etree.ElementTree
#UPDATE
address="http://epicollectserver.appspot.com/getMapXML?projectKey=ahZzfmVwaWNvbGxlY3RzZXJ2ZXItaHJkchQLEgdQcm9qZWN0GICAgO7L-YsKDA"
Remote_XML = urllib2.urlopen(address)
Local="Local_XML.xml"
New=open(Local,"w")
New.write(Remote_XML.read())
New.close()
#READ
e = xml.etree.ElementTree.parse(Local).getroot()
print "Total records are ", len(e)
feats = []
for record in e.findall("Record"):
rec=0
for itemo in xrange(len(record)):
print e[rec][itemo].tag
print record[itemo].text
if e[rec][itemo].tag=="id":
ID=record[itemo].text
if e[rec][itemo].tag=="ecPhotoPath":
if record[itemo].text:
urllib.urlretrieve(record[itemo].text, ID+"_"+str(rec)+".jpg")
print "****"
rec+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment