from linkedin import linkedin
import oauthlib

class Linkedinviewer (object):

	def __init__ (self, cred_file):
		self.cred_file = cred_file
		self.authentication = None
		self.application = None

	def authenticate(self):

		# Define CONSUMER_KEY, CONSUMER_SECRET,  
		# USER_TOKEN, and USER_SECRET from the credentials 
		# provided in your LinkedIn application

		cred_list = []
		with open(self.cred_file, 'r') as f:
			cred_data = f.readlines()
			for line in cred_data:
				try:
					cred_temp = line.split('=')[1]
				except:
					print "Bad credentials for LinkedIn api authentication"
				cred_list.append(cred_temp.strip(' \t\n\r'))

		# Authenticating with LinkedIn

		try:
			self.authentication = linkedin.LinkedInDeveloperAuthentication(cred_list[0], cred_list[1], cred_list[2],
														cred_list[3], cred_list[4], linkedin.PERMISSIONS.enums.values())
			self.application = application = linkedin.LinkedInApplication(self.authentication)
		except:
			print "Failed to authenticate with LinkedIn"


	def get_profile(self):
		
		# Get profile information
		profile = self.application.get_profile()
		print profile

		return profile

	def get_company(self, company_id=None, universal_names=[]):

		# Get company information
		companies = self.application.get_companies(company_id, universal_names)
		print companies

		return companies

	def get_company_updates(self, company_id=None, count=1):

		# Get company updates
		company_updates = self.application.get_company_updates(company_id, params={'count': count})
		print company_updates

		return company_updates

if __name__ == "__main__":
	lviewer = Linkedinviewer('linkedincred.conf')
	lviewer.authenticate()
	lviewer.get_profile()
	companies = lviewer.get_company(universal_names=['splunk'])
	company_list = []
	for i in range(companies['_total']):
		company_list.append(companies['values'][i])
	for company in company_list:
		lviewer.get_company_updates(company_id=company['id'], count=5)
@@ -224,122 +224,25 @@
 %09%09# 
-Define CONSUMER_KEY, CONSUMER_SECRET,  %0A%09%09# USER_TOKEN, and USER_SECRET from the credentials %0A%09%09# provided in your
+Authenticate with
  Lin
@@ -254,17 +254,19 @@
  app
-lication%0A
+ credential
 %0A%09%09c
@@ -276,18 +276,20 @@
 _list = 
-%5B%5D
+None
 %0A%09%09with 
@@ -493,16 +493,67 @@
 cation%22%0A
+%09%09%09%09%0A%09%09%09%09if cred_list is None:%0A%09%09%09%09%09cred_list = %5B%5D%0A
 %09%09%09%09cred
@@ -967,16 +967,30 @@
 kedIn%22%0A%0A
+%09%09return None%0A
 %0A%09def ge
@@ -1171,18 +1171,20 @@
 l_names=
-%5B%5D
+None
 ):%0A%0A%09%09# 
@@ -1353,28 +1353,27 @@
 self, compan
-y_id
+ies
 =None, count
@@ -1412,23 +1412,385 @@
 company_
-updates
+list = None%0A%09%09company_updates_dict = None%0A%09%09%0A%09%09print 'test'%0A%09%09if companies is not None:%0A%09%09%09for i in range(companies%5B'_total'%5D):%0A%09%09%09%09if company_list is None:%0A%09%09%09%09%09company_list = %5B%5D%0A%09%09%09%09company_list.append(companies%5B'values'%5D%5Bi%5D)%0A%09%09%09for company in company_list:%0A%09%09%09%09if company_updates_dict is None:%0A%09%09%09%09%09company_updates_dict = %7B%7D%0A%09%09%09%09company_updates_dict%5Bcompany%5B'name'%5D%5D
  = self.
@@ -1828,19 +1828,22 @@
 (company
-_id
+%5B'id'%5D
 , params
@@ -1867,29 +1867,329 @@
 )%0A%09%09
-print company_updates
+%09for company_name, company_updates in company_updates_dict.iteritems():%0A%09%09%09%09print '%5Cn************************', company_name, '************************%5Cn'%0A%09%09%09%09for i in range(company_updates%5B'_count'%5D):%0A%09%09%09%09%09print '========================%5Cn'%0A%09%09%09%09%09print company_updates%5B'values'%5D%5Bi%5D%0A%09%09%09%09%09print '%5Cn========================'
 %0A%0A%09%09
@@ -2210,16 +2210,21 @@
 _updates
+_dict
 %0A%0Aif __n
@@ -2388,16 +2388,25 @@
 _names=%5B
+'apple', 
 'splunk'
@@ -2421,134 +2421,23 @@
 any_
-list = %5B%5D%0A%09for i in range(companies%5B'_total'%5D):%0A%09%09company_list.append(companies%5B'values'%5D%5Bi%5D)%0A%09for company in company_list:%0A%09%09
+updates_dict = 
 lvie
@@ -2470,32 +2470,27 @@
 mpan
-y_id
+ies
 =compan
-y%5B'id'%5D
+ies
 , count=
 5)
@@ -2491,6 +2491,6 @@
 unt=
-5
+3
 )

update linkedinviewer for multiple company updates