Skip to content
Browse files

added parsers for twitter-accounts and member-url-resources fields fr…

…om linkedin profiles
  • Loading branch information...
1 parent 8e2a481 commit cdb71e70144bb1e27584d267d0a59cc3f74375cb philgo20 committed Jan 5, 2011
Showing with 82 additions and 5 deletions.
  1. +53 −2 liclient/parsers/lixml.py
  2. +29 −3 liclient/parsers/mappers.py
View
55 liclient/parsers/lixml.py
@@ -13,7 +13,9 @@ def __init__(self, content):
'error': self.__parse_error,
'position': self.__parse_position,
'education': self.__parse_education,
- 'people': self.__parse_people_collection
+ 'people': self.__parse_people_collection,
+ 'twitter-account': self.__parse_twitter_accounts,
+ 'member-url': self.__parse_member_url_resources
}
self.tree = etree.fromstring(content)
self.root = self.tree.tag
@@ -49,6 +51,14 @@ def __parse_position(self, tree):
def __parse_education(self, tree):
content = LinkedInEducationParser(tree).results
+ return content
+
+ def __parse_twitter_accounts(self, tree):
+ content = LinkedInTwitterAccountParser(tree).results
+ return content
+
+ def __parse_member_url_resources(self, tree):
+ content = LinkedInMemberUrlResourceParser(tree).results
return content
def __parse_people_collection(self, tree):
@@ -272,4 +282,45 @@ 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
+ self.xpath_collection = {
+ 'provider-account-id': etree.XPath('provider-account-id'),
+ 'provider-account-name': etree.XPath('provider-account-name'),
+ }
+ self.results = self.__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
+ results = mappers.TwitterAccount(data, tree)
+ 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):
+ 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
+ results = mappers.MemberUrlResource(data, tree)
+ return results
+
+
View
32 liclient/parsers/mappers.py
@@ -219,11 +219,15 @@ def __init__(self, data, xml):
self.xml = xml
self.parse_data(data)
self.positions = []
- self.educations = []
+ self.educations = []
+ self.twitter_accounts = []
+ self.member_url_resources = []
if not self.profile_url:
self.set_profile_url()
self.get_positions()
- self.get_educations()
+ self.get_educations()
+ self.get_twitter_accounts()
+ self.get_member_url_resources()
def set_profile_url(self):
try:
@@ -244,10 +248,32 @@ def get_educations(self):
eds = profile_education_xpath(self.xml)
for e in eds:
obj = lixml.LinkedInXMLParser(etree.tostring(e)).results
- self.educations.append(obj)
+ self.educations.append(obj)
+
+ def get_twitter_accounts(self):
+ twitter_accounts_xpath = etree.XPath('twitter-accounts/twitter-account')
+ accounts = twitter_accounts_xpath(self.xml)
+ for account in accounts:
+ obj = lixml.LinkedInXMLParser(etree.tostring(account)).results
+ self.twitter_accounts.append(obj)
+
+ def get_member_url_resources(self):
+ url_resources_xpath = etree.XPath('member-url-resources/member-url')
+ urls = url_resources_xpath(self.xml)
+ for url in urls:
+ obj = lixml.LinkedInXMLParser(etree.tostring(url)).results
+ self.member_url_resources.append(obj)
+
+
class Position(LinkedInData):
pass
class Education(LinkedInData):
+ pass
+
+class TwitterAccount(LinkedInData):
+ pass
+
+class MemberUrlResource(LinkedInData):
pass

0 comments on commit cdb71e7

Please sign in to comment.
Something went wrong with that request. Please try again.