Created
November 29, 2016 18:29
-
-
Save mveinot/89257387f030e9479bda5f1d41bab9ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
import untangle | |
doc = untangle.parse('/home/gpeverill/bryden.xml') | |
# use python's handy 'for item in list' syntax to traverse the list of Assets | |
for asset in doc.root.Dealership.Assets.Asset: | |
# save the VIN cdata value to a variable and print it | |
vin = asset.VIN.cdata | |
print ('VIN: '+vin) | |
# some Assets have no pictures which causes an IndexError exception when you try to access the object | |
# we surround the "dangerous" code with a try: block | |
try: | |
for picture in asset.Pictures.Picture: | |
print ('\t'+picture['Url']) | |
# if the above code throws IndexError, we catch it and use that opportunity to inform that there are no pictures | |
except IndexError: | |
print ("\tNo Pictures") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment