Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use the new people-search api, deal with hierarchical data (badly)

  • Loading branch information...
commit fe782195be4707d70a843fb55fb4f656e1fd550f 1 parent 0bc7cd7
@jsundram jsundram authored
Showing with 31 additions and 2 deletions.
  1. +31 −2 liclient/parsers/lixml.py
View
33 liclient/parsers/lixml.py
@@ -13,7 +13,7 @@ def __init__(self, content):
'error': self.__parse_error,
'position': self.__parse_position,
'education': self.__parse_education,
- 'people': self.__parse_people_collection
+ 'people-search': self.__parse_people_collection
}
self.tree = etree.fromstring(content)
self.root = self.tree.tag
@@ -52,7 +52,8 @@ def __parse_education(self, tree):
return content
def __parse_people_collection(self, tree):
- ppl = tree.getchildren()
+ ppl, n = tree.getchildren()
+ result_count = int(n.text)
content = []
for p in ppl:
rslts = LinkedInProfileParser(p).results
@@ -167,8 +168,36 @@ def __build_data(self, tree):
person[re.sub(r'-', '_', item.tag)] = item.text
obj = mappers.Profile(person, p)
results.append(obj)
+
+ # deal with hierarchical results in a somewhat kludgy way
+ def fix(s):
+ return re.sub(r'-', '_', s)
+ def build_name(parent, item):
+ s = ''
+ p = item.getparent()
+ while p != parent:
+ s = fix(p.tag) + '_' + s
+ p = p.getparent()
+ s += fix(item.tag)
+ return s
if not results:
person = {}
+ for item in tree.iterdescendants():
+ clean = item.text and item.text.strip()
+ if clean:
+ name = build_name(tree, item)
+ if name in person:
+ value = person[name]
+ if type(value) != list:
+ person[name] = [value, clean]
+ else:
+ person[name].append(clean)
+ else:
+ person[name] = clean
+ obj = mappers.Profile(person, tree)
+ results.append(obj)
+ if False: #not results: # the original, elegant but wrong way
+ person = {}
for item in tree.getchildren():
person[re.sub(r'-', '_', item.tag)] = item.text
obj = mappers.Profile(person, tree)
Please sign in to comment.
Something went wrong with that request. Please try again.