Created
January 30, 2012 04:32
-
-
Save harperreed/1702550 to your computer and use it in GitHub Desktop.
a def to turn pesterfish object into an associative object
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
def fix_pesterfish(data): | |
result = {} | |
if type(data)==list: | |
for d in data: | |
try: | |
result[d['tag']]=fix_pesterfish(d['children']) | |
except: | |
try: | |
result[d['tag']]=d['text'] | |
except: | |
try: | |
if d['attributes']: | |
if type(result[d['tag']]) != list: | |
l = [] | |
result[d['tag']] = l | |
result[d['tag']].append(d['attributes']) | |
except: | |
result[d['tag']]='' | |
else: | |
try: | |
result[data['tag']]=fix_pesterfish(data['children']) | |
except: | |
try: | |
result[data['tag']]=data['text'] | |
except: | |
result[data['tag']]='' | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment