Permalink
Browse files

Merge https://github.com/PhilGo20/LinkedIn-Client-Library into PhilGo…

…20-master

Conflicts:
	liclient/parsers/lixml.py
  • Loading branch information...
unknown
unknown committed Jul 6, 2011
2 parents 58e7f85 + 775fd06 commit 6f5f1b1eb418e7f7ba67f23cd3fb80308683bbec
Showing with 72 additions and 35 deletions.
  1. +4 −7 liclient/__init__.py
  2. +52 −25 liclient/parsers/lixml.py
  3. +16 −3 liclient/parsers/mappers.py
View
@@ -91,14 +91,11 @@ def get_user_connections(self, access_token, selectors=None, **kwargs):
are automatically converted from integer to string for URL formatting
if necessary.
"""
-
- user_token, url = self.prepare_request(access_token, self.api_profile_connections_url, kwargs)
+ if selectors:
+ url = self.prepare_field_selectors(selectors, self.api_profile_connections_url)
+ user_token, url = self.prepare_request(access_token, url, kwargs)
client = oauth.Client(self.consumer, user_token)
- if not selectors:
- resp, content = client.request(url, 'GET')
- else:
- url = self.prepare_field_selectors(selectors, url)
- resp, content = client.request(url, 'GET')
+ resp, content = client.request(url, 'GET')
content = self.clean_dates(content)
return LinkedInXMLParser(content).results
View
@@ -12,11 +12,11 @@ def __init__(self, content):
'connections': self.__parse_connections,
'error': self.__parse_error,
'position': self.__parse_position,
- 'education': self.__parse_education,
- 'people-search': self.__parse_people_collection,
- 'people': self.__parse_people_collection,
- 'twitter-account': self.__parse_twitter_accounts,
- 'member-url': self.__parse_member_url_resources
+ 'skill': self.__parse_skills,
+ 'education': self.__parse_education,
+ '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
@@ -41,6 +41,10 @@ def __parse_update_comments(self, tree):
def __parse_connections(self, tree):
content = LinkedInConnectionsParser(tree).results
return content
+
+ def __parse_skills(self, tree):
+ content = LinkedInSkillsParser(tree).results
+ return content
def __parse_error(self, tree):
content = LinkedInErrorParser(tree).results
@@ -52,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
@@ -274,19 +278,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
@@ -312,9 +316,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
@@ -325,19 +329,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):
@@ -348,6 +352,29 @@ def __build_data(self, tree):
else:
data[re.sub('-', '_', n.tag)] = n.getchildren()[0].text
results = mappers.MemberUrlResource(data, tree)
- return results
-
-
+ return results
+
+<<<<<<< HEAD
+
+=======
+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):
+ 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.Skills(data, tree)
+ return results
+
+
+>>>>>>> 775fd061e4f243ae37b4aa1e3b3e6e39c3dacff8

This comment has been minimized.

Show comment Hide comment
@sidmitra

sidmitra Jul 6, 2011

Hey the merge markers made it into the code? lol broke a production app of mine where i accidently used this repo directly in the pip requirements.txt DOH!!

@sidmitra

sidmitra Jul 6, 2011

Hey the merge markers made it into the code? lol broke a production app of mine where i accidently used this repo directly in the pip requirements.txt DOH!!

This comment has been minimized.

Show comment Hide comment
@mrgaaron

mrgaaron Jul 6, 2011

Owner

Wow how did I miss that. Embarrassing. Just pushed a cleaned version

@mrgaaron

mrgaaron Jul 6, 2011

Owner

Wow how did I miss that. Embarrassing. Just pushed a cleaned version

This comment has been minimized.

Show comment Hide comment
@sidmitra

sidmitra Jul 6, 2011

:-) been there!

@sidmitra

sidmitra Jul 6, 2011

:-) been there!

@@ -218,14 +218,16 @@ def __init__(self, data, xml):
self.profile_url = ''
self.xml = xml
self.parse_data(data)
- self.positions = []
+ self.positions = []
+ self.skills = []
self.educations = []
self.twitter_accounts = []
self.member_url_resources = []
if not self.profile_url:
self.set_profile_url()
self.get_location()
- self.get_positions()
+ self.get_positions()
+ self.get_skills()
self.get_educations()
self.get_twitter_accounts()
self.get_member_url_resources()
@@ -251,7 +253,15 @@ def get_positions(self):
pos = profile_position_xpath(self.xml)
for p in pos:
obj = lixml.LinkedInXMLParser(etree.tostring(p)).results
- self.positions.append(obj)
+ self.positions.append(obj)
+
+ def get_skills(self):
+
+ profile_skills_xpath = etree.XPath('skills/skill')
+ skills = profile_skills_xpath(self.xml)
+ for s in skills:
+ obj = lixml.LinkedInXMLParser(etree.tostring(s)).results
+ self.skills.append(obj)
def get_educations(self):
profile_education_xpath = etree.XPath('educations/education')
@@ -284,6 +294,9 @@ class Education(LinkedInData):
class TwitterAccount(LinkedInData):
pass
+
+class Skills(LinkedInData):
+ pass
class MemberUrlResource(LinkedInData):
pass

0 comments on commit 6f5f1b1

Please sign in to comment.