Permalink
Browse files

Merge pull request #2 from votizen/master

fixing date-of-birth processing for JSON
  • Loading branch information...
2 parents d767350 + 484e110 commit 4f11278d8e3e78175308d2f5de56473fd0e11a59 phil gauvin committed Feb 8, 2012
Showing with 41 additions and 29 deletions.
  1. +41 −29 liclient/parsers/lixml.py
View
@@ -11,11 +11,11 @@ def __init__(self, content):
'update-comments': self.__parse_update_comments,
'connections': self.__parse_connections,
'error': self.__parse_error,
- 'position': self.__parse_position,
+ 'position': self.__parse_position,
'skill': self.__parse_skills,
'education': self.__parse_education,
- 'people': self.__parse_people_collection,
- 'twitter-account': self.__parse_twitter_accounts,
+ 'people': self.__parse_people_collection,
+ 'twitter-account': self.__parse_twitter_accounts,
'member-url': self.__parse_member_url_resources
}
self.tree = etree.fromstring(content)
@@ -40,8 +40,8 @@ def __parse_update_comments(self, tree):
def __parse_connections(self, tree):
content = LinkedInConnectionsParser(tree).results
- return content
-
+ return content
+
def __parse_skills(self, tree):
content = LinkedInSkillsParser(tree).results
return content
@@ -56,12 +56,12 @@ def __parse_position(self, tree):
def __parse_education(self, tree):
content = LinkedInEducationParser(tree).results
- return content
-
+ return content
+
def __parse_twitter_accounts(self, tree):
content = LinkedInTwitterAccountParser(tree).results
- return content
-
+ return content
+
def __parse_member_url_resources(self, tree):
content = LinkedInMemberUrlResourceParser(tree).results
return content
@@ -178,6 +178,18 @@ def __build_data(self, tree):
for item in p.getchildren():
if item.tag == 'location':
person['location'] = item.getchildren()[0].text
+ elif item.tag == 'date-of-birth':
+ temp_obj = {}
+ for dob_item in item.getchildren():
+ temp_obj[dob_item.tag] = dob_item.text
+
+ if temp_obj.get('day') and temp_obj.get('month') and temp_obj.get('year'):
+ person['date_of_birth'] = '/'.join(
+ (temp_obj.get('month'),temp_obj.get('day'),temp_obj.get('year'),)
+ )
+ else:
+ # skip when no year
+ pass
else:
person[re.sub(r'-', '_', item.tag)] = item.text
obj = mappers.Profile(person, p)
@@ -249,19 +261,19 @@ def __init__(self, content):
'title': etree.XPath('title'),
'summary': etree.XPath('summary'),
'start-date-year': etree.XPath('start-date/year'),
- 'end-date-year': etree.XPath('end-date/year'),
+ 'end-date-year': etree.XPath('end-date/year'),
'start-date-month': etree.XPath('start-date/month'),
'end-date-month': etree.XPath('end-date/month'),
- 'is-current': etree.XPath('is-current'),
+ 'is-current': etree.XPath('is-current'),
'company-id': etree.XPath('company/id'),
'company': etree.XPath('company/name')
}
self.results = self.__build_data(self.tree)
def __build_data(self, tree):
- data = dict(
- [(re.sub('-','_',key),self.xpath_collection[key](tree)[0].text) for key in self.xpath_collection if len(self.xpath_collection[key](tree)) > 0]
- )
+ data = dict(
+ [(re.sub('-','_',key),self.xpath_collection[key](tree)[0].text) for key in self.xpath_collection if len(self.xpath_collection[key](tree)) > 0]
+ )
results = mappers.Position(data, tree)
return results
@@ -287,9 +299,9 @@ def __build_data(self, tree):
else:
data[re.sub('-', '_', n.tag)] = n.getchildren()[0].text
results = mappers.Education(data, tree)
- return results
-
-
+ return results
+
+
class LinkedInTwitterAccountParser(LinkedInXMLParser):
def __init__(self, content):
self.tree = content
@@ -300,19 +312,19 @@ def __init__(self, content):
self.results = self.__build_data(self.tree)
def __build_data(self, tree):
- data = dict(
- [(re.sub('-','_',key),self.xpath_collection[key](tree)[0].text) for key in self.xpath_collection if len(self.xpath_collection[key](tree)) > 0]
+ data = dict(
+ [(re.sub('-','_',key),self.xpath_collection[key](tree)[0].text) for key in self.xpath_collection if len(self.xpath_collection[key](tree)) > 0]
)
results = mappers.TwitterAccount(data, tree)
- return results
-
+ return results
+
class LinkedInMemberUrlResourceParser(LinkedInXMLParser):
def __init__(self, content):
self.tree = content
self.xpath_collection = {
'url': etree.XPath('url'),
'name': etree.XPath('name'),
- }
+ }
self.results = self.__build_data(self.tree)
def __build_data(self, tree):
@@ -323,25 +335,25 @@ def __build_data(self, tree):
else:
data[re.sub('-', '_', n.tag)] = n.getchildren()[0].text
results = mappers.MemberUrlResource(data, tree)
- return results
-
+ return results
+
class LinkedInSkillsParser(LinkedInXMLParser):
def __init__(self, content):
self.tree = content
self.xpath_collection = {
'id': etree.XPath('id'),
'name': etree.XPath('skill/name'),
- }
+ }
self.results = self.__build_data(self.tree)
- def __build_data(self, tree):
+ def __build_data(self, tree):
data = {}
for n in tree.getchildren():
if not n.getchildren():
data[re.sub('-', '_', n.tag)] = n.text
else:
- data[re.sub('-', '_', n.tag)] = n.getchildren()[0].text
+ data[re.sub('-', '_', n.tag)] = n.getchildren()[0].text
results = mappers.Skills(data, tree)
- return results
-
+ return results
+

0 comments on commit 4f11278

Please sign in to comment.