Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No files_attached #24

Open
newnativeabq opened this issue Jul 23, 2019 · 0 comments
Open

No files_attached #24

newnativeabq opened this issue Jul 23, 2019 · 0 comments

Comments

@newnativeabq
Copy link

mendeley.models.catalog.CatalogAllDocument.file_attached returns False for all documents.

Similarly, mendeley.models.catalog.CatalogAllDocument.files.iter() yields null generator that will force Mendeley API to throw a 404 not found.

`
import client

def searchMendeley(query, session=None, close ='yes'):
'''
Searches mendeley catalog with given query term on existing session.
Session must be authenticated with startSession() prior.
Returns an iterable catalog search object and the session object search, session
'''
if session == None:
session = client.startSession()

search = session.catalog.search(query=query, view='all').iter()

if (close == 'yes') and (session != None):
    client.closeSession(session)

return search, session

def getFiles(doc_obj):
'''
Takes a single mendeley.catalog.doc object obtained in catalog.search.
Returns an iterable files object that can be searched for files

Returns list of file_names
'''

# Create a files iterator
files = doc_obj.files

def checkFiles(file_iter):
    '''
    Iterate through mendeley.resources.files.Files object and report information.
    ** Having activity scoped here allows try statement to pick up on API errors.
    '''
    for count, file in enumerate(file_iter):
        print(count)
        return count

try:
    checkFiles(files)
except:
    print('File Search Failed')

return files

def buildSearchDict(search_obj, num_docs=10):
'''
Takes a mendeley.catalog.search object and returns a dictionary of
documents and file objects.
'''
search_dict = {}
for count, doc in enumerate(search_obj):
print('checking document', count, ':', doc.file_attached)
if count >= num_docs:
break
if not doc.file_attached:
search_dict[type(doc)] = doc.file_attached
return search_dict
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant