Beispiel #1
0
class MendeleyImporter:
	#parameters are OAuth keys
	def __init__(self, consumer_key, secret_key):
		self.mendeley = MendeleyClient(consumer_key, secret_key)
	
	#fetches URL for authenticating tokens
	def get_auth_url(self):
		self.mendeley.request_token = self.mendeley.mendeley.request_token()
		return(self.mendeley.mendeley.authorize(self.mendeley.request_token))
	
	#loads authenticated OAuth tokens
	def load_keys(self, api_keys_pkl_dir):
		#dirty hack
		tmp_cwd = os.getcwd()
		os.chdir(api_keys_pkl_dir)
		self.mendeley.load_keys()
		os.chdir(tmp_cwd)
	#dumps authenticated OAuth tokens to file
	def save_keys(self, api_keys_pkl_dir):
		#same dirty hack as before
		tmp_cwd = os.getcwd()
		os.chdir(api_keys_pkl_dir)
		self.mendeley.save_keys()
		os.chdir(tmp_cwd)
	
	#get dictionary with folder IDs and names
	def get_folders(self):
		return self.mendeley.folders()
	
	#get list of dictionarys with document details from given folder, or all documents if folder_id is 0
	def get_documents(self, folder_id):
		list_result = []
		#get document_ids for docs in given folder
		if folder_id == 0:
			#all documents
			fold = self.mendeley.library()
		else:
			fold = self.mendeley.folder_documents(folder_id)
		#get details for document_ids
		for doc in fold['document_ids']:
			doc_details = self.mendeley.document_details(doc)
			if not 'citation_key' in doc_details:
				#awkward, mendeley did not give citation_key
				#let's be creative and generate one
				doc_details['citation_key'] = ''
				if doc_details['authors']!=[]:
					doc_details['citation_key'] += doc_details['authors'][0]['surname']
				if 'year' in doc_details:
					doc_details['citation_key'] += doc_details['year']+'_'
				doc_details['citation_key'] += doc_details['id']
			list_result.append(doc_details)
		return list_result
	
	# parses serialized request token and the verifier that was given by user
	def set_verified_token(self, token_string, verifier):
		self.mendeley.request_token = oauth2.Token.from_string(token_string)
		self.mendeley.mendeley.authorize(self.mendeley.request_token)
		self.mendeley.request_token.set_verifier(verifier)
		self.mendeley.access_token = self.mendeley.mendeley.access_token(self.mendeley.request_token)
Beispiel #2
0
print """

-----------------------------------------------------
My Library publication statistics
-----------------------------------------------------"""
response = mendeley.library_publication_stats()
pprint(response)

### Library ###
print 'Library'
print """

-----------------------------------------------------
My Library documents
-----------------------------------------------------"""
documents = mendeley.library()
pprint(documents)

print """

-----------------------------------------------------
Create a new library document
-----------------------------------------------------"""
response = mendeley.create_document(document=json.dumps({'type' : 'Book','title': 'Document creation test', 'year': 2008}))
pprint(response)
documentId = response['document_id']

print """

-----------------------------------------------------
Document details