Пример #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)
Пример #2
0
 def auth_mendeley(self):
   from mendeley_client import MendeleyClient
   mendeley = MendeleyClient(XXXXXXX, XXXXXXX) #get from dev.mendeley.com
   try:
       mendeley.load_keys()
   except IOError:
       mendeley.get_required_keys()
       mendeley.save_keys()
   return mendeley
Пример #3
0
def get_mendeley_authored_documents():
    '''This function gets all of the authored documents in the authorized library.
    
    It will return a dictionary named documents with keys documentId and several fields from the Mendeley API.
    '''
    mendeley = MendeleyClient(settings.MENDELEY_CONSUMER_KEY,
                              settings.MENDELEY_SECRET_KEY)

    try:
        mendeley.load_keys()
    except IOError:
        mendeley.get_required_keys()
        mendeley.save_keys()
    authored_document_list = {}
    response = mendeley.documents_authored(
    )  #this get a list of all documents authored by the authorized user
    for document in response[
            'document_ids']:  #this generates a list of all the details for each of these documents
        details = mendeley.document_details(document)
        authored_document_list[document] = details
    return authored_document_list
Пример #4
0
def get_mendeley_authored_documents():
    '''This function gets all of the authored documents in the authorized library.
    
    It will return a dictionary named documents with keys documentId and several fields from the Mendeley API.
    '''
    mendeley = MendeleyClient(settings.MENDELEY_CONSUMER_KEY, settings.MENDELEY_SECRET_KEY)

    try:
        mendeley.load_keys()
    except IOError:
        mendeley.get_required_keys()
        mendeley.save_keys()
    authored_document_list = {}
    response = mendeley.documents_authored() #this get a list of all documents authored by the authorized user
    for document in response['document_ids']: #this generates a list of all the details for each of these documents
        details = mendeley.document_details(document)
        authored_document_list[document] = details
    return authored_document_list
python test-download.py

"""

from pprint import pprint
from mendeley_client import MendeleyClient
import json
import os
import sys
import string
import httplib


#mendeley = MendeleyClient('<insert_consumer_key_here>', '<insert_secret_key_here>')
mendeley = MendeleyClient('9a65b12d6eae277d5212a1205f57d5cc04fcc5392', 'e9b021c12e732c279c6f48a5cbcb99e5')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()

docId = raw_input('Insert document id: ')
fileHash = raw_input('Insert file hash: ')
## If you want to download a group document, then introduce the group id and then call download_file_group instead 
#groupId = raw_input('Insert group id: ')

response = mendeley.download_file(docId, fileHash)

#if response.has_key('error'):
For details of the Mendeley Open API see http://dev.mendeley.com/

Example usage:

python test.py

"""

from pprint import pprint
from mendeley_client import MendeleyClient
import json
# import os
import string
# import sys

mendeley = MendeleyClient('13a47f20711f5d5ffe8e8f4db1df1daa04f8bd9b6',
                          '394d64a2907f23c7f6ea5d94fb386865')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()


class MPub(object):
    def __init__(self, uuid, title, abstract, authors, keywords, publication,
                 tags, url, year):
        self.uuid = uuid
        self.title = title
        self.abstract = abstract
        self.authors = authors
Пример #7
0
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

For details of the Mendeley Open API see http://dev.mendeley.com/

Example usage:

python test.py

"""

from pprint import pprint
from mendeley_client import MendeleyClient
import json
import os

mendeley = MendeleyClient('<insert_consumer_key_here>', '<insert_secret_key_here>')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()

########################################
######## Public Resources Tests ########
########################################

print """

-----------------------------------------------------
Canonical document details
Пример #8
0
# for i = 1 to (documents in group)

# search for n documents related to i and date gt update since

# if n > 0 increment docsupdated counter by 1 and increment totaldocstoreview by n

# save documents 1...n in group (subgroup for review)

# save document titles 1...n to file

# report

#checked n documents from group name

# there were new citations related to docsupdated

# totalsdocs to review have been added to group(for review)

from pprint import pprint
from mendeley_client import MendeleyClient
mendeley = MendeleyClient('13a47f20711f5d5ffe8e8f4db1df1daa04f8bd9b6',
                          '394d64a2907f23c7f6ea5d94fb386865')
try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()

folders = mendeley.group_folders(groupId)
pprint(folders)
Пример #9
0
@author: marcuni
'''

from mendeley_client import MendeleyClientConfig, MendeleyClient, MendeleyTokensStore
import os
import sys
import shutil

# Load the configuration file
config = MendeleyClientConfig()
if not config.is_valid():
    print "Please edit config.json before running this script"
    sys.exit(1)

# create a client and load tokens from the pkl file
mendeley = MendeleyClient(config.api_key, config.api_secret)
tokens_store = MendeleyTokensStore()

# configure the client to use a specific token
# if no tokens are available, prompt the user to authenticate
access_token = tokens_store.get_access_token("test_account")
if not access_token:
    mendeley.interactive_auth()
    tokens_store.add_account("test_account",mendeley.get_access_token())
else:
    mendeley.set_access_token(access_token)


documents = mendeley.folder_documents(34240081)['document_ids']

for document_id in documents:
Пример #10
0
from mendeley_client import MendeleyClient
import cPickle as pickle

mendeley = MendeleyClient('f37044bebbda140b8ad9a7a923588a84051253aa2','0038b670aa7e4ec9e4aaf441599bec13')
##mendeley = MendeleyClient('<consumer_key>', '<secret_key>')
mendeley.load_keys()
data = pickle.load(open('mendeley_api_keys.pkl', 'r'))

request_token = data['request_token']
access_token = data['access_token']

groupId = '2058663'

print sorted(mendeley.__dict__.keys())
response = mendeley.group_documents(groupId, items=1000)
docs = response['document_ids']
print docs

all_docs = {}
for doc in docs:
    response = mendeley.group_doc_details(groupId, doc)
    url = response['mendeley_url']
    all_docs[url] = response
    print url, response

pickle.dump(all_docs, open('group_docs.pkl', 'wb'))
Пример #11
0
Created on 27 aug 2012

@author: marcuni
'''

from mendeley_client import MendeleyClientConfig, MendeleyClient, MendeleyTokensStore
import sys

# Load the configuration file
config = MendeleyClientConfig()
if not config.is_valid():
    print "Please edit config.json before running this script"
    sys.exit(1)

# create a client and load tokens from the pkl file
mendeley = MendeleyClient(config.api_key, config.api_secret)
tokens_store = MendeleyTokensStore()

# configure the client to use a specific token
# if no tokens are available, prompt the user to authenticate
access_token = tokens_store.get_access_token("test_account")
if not access_token:
    mendeley.interactive_auth()
    tokens_store.add_account("test_account",mendeley.get_access_token())
else:
    mendeley.set_access_token(access_token)


theFolders = mendeley.folders()

for folder in theFolders:
Пример #12
0
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

For details of the Mendeley Open API see http://dev.mendeley.com/

Example usage:

python test.py

"""

from pprint import pprint
from mendeley_client import MendeleyClient
import json
#import os

mendeley = MendeleyClient('13a47f20711f5d5ffe8e8f4db1df1daa04f8bd9b6',
                          '394d64a2907f23c7f6ea5d94fb386865')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()

searchterm = raw_input('Enter search term: ')
pprint(searchterm)

documents = mendeley.search(searchterm, items=20)
pprint(documents)

documents = mendeley.search(searchterm, items=20)
for i in range(0, len(documents)):
Пример #13
0
	def __init__(self, consumer_key, secret_key):
		self.mendeley = MendeleyClient(consumer_key, secret_key)
Example usage:

python test.py

"""

from pprint import pprint
from mendeley_client import MendeleyClient
import json
# import os
import string
# import sys


mendeley = MendeleyClient('13a47f20711f5d5ffe8e8f4db1df1daa04f8bd9b6', '394d64a2907f23c7f6ea5d94fb386865')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()

class MPub(object):
    
    def __init__(self, uuid, title, abstract, authors, keywords, publication, tags, url, year):
        self.uuid = uuid
        self.title = title
        self.abstract = abstract
        self.authors = authors
        self.keywords = keywords
Пример #15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from mendeley_client import MendeleyClient

# Renomeie o arquivo para mendeley.py após adicionar as chaves abaixo!
mendeley = MendeleyClient('<consumer_key>', '<secret_key>')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

For details of the Mendeley Open API see http://dev.mendeley.com/

Example usage:

python test.py

"""

from pprint import pprint
from mendeley_client import MendeleyClient
import json
#import os

mendeley = MendeleyClient('13a47f20711f5d5ffe8e8f4db1df1daa04f8bd9b6', '394d64a2907f23c7f6ea5d94fb386865')

try:
    mendeley.load_keys()
except IOError:
    mendeley.get_required_keys()
    mendeley.save_keys()



searchterm = raw_input('Enter search term: ')
pprint(searchterm)

documents = mendeley.search(searchterm, items=20)
pprint(documents)