Permalink
Browse files

Fixed a bug in poll_profiles

  • Loading branch information...
1 parent 2bf1321 commit b051c43bb3f5c4ee951c5cbdc8f21aa7ef329ee4 Szymon Guz committed Mar 12, 2013
Showing with 31 additions and 25 deletions.
  1. +31 −25 scripts/poll_profiles
View
@@ -268,32 +268,38 @@ def process_edan_all(profile, blacklist=None):
desc_non = item["descriptiveNonRepeating"]
item["_id"] = desc_non["record_ID"]
- hier_items = item["freetext"]
-
- for k, v in hier_items.items():
- x = (v if isinstance(v, list) else [v])
-
- for hi in x:
- if not '@label' in hi:
- continue
- hid = hi['@label']
- htitle = hi['#text']
-
- if hid not in collections:
- # Grab series information from item
- coll = {}
- coll['id'] = hid
- coll['title'] = htitle
- coll['items'] = []
- collections[hid] = coll
- else:
- coll = collections[hid]
+ freetext = item["freetext"]
+
+ if not "setName" in freetext: # So there is no collection
+ return True #XML parser need to get True here to continue parsing
+
+ colls = freetext["setName"]
+ it = colls
+ if not isinstance(colls, list):
+ it = [colls]
+
+ for c in it:
+ if not "#text" in c:
+ continue
+
+ hid = c["#text"]
+ htitle = c["#text"]
+
+ if hid not in collections:
+ # Grab series information from item
+ coll = {}
+ coll['id'] = hid
+ coll['title'] = htitle
+ coll['items'] = []
+ collections[hid] = coll
+ else:
+ coll = collections[hid]
- # Create tmp file to hold collections items
- coll_fn = cache_file_name(cache_dir, coll['id'])
- coll_f = open(coll_fn,'a')
- coll_f.write(str(item)+"\n")
- coll_f.close()
+ # Create tmp file to hold collections items
+ coll_fn = cache_file_name(cache_dir, coll['id'])
+ coll_f = open(coll_fn,'a')
+ coll_f.write(str(item)+"\n")
+ coll_f.close()
return True

0 comments on commit b051c43

Please sign in to comment.