Skip to content
Browse files

updated to allow caching

  • Loading branch information...
1 parent e848ba2 commit 859af520dcf5de79a94eff1bc240c528a4a05214 @cboettig committed Jul 16, 2013
Showing with 20 additions and 18 deletions.
  1. +20 −18 mendeley.rb
View
38 mendeley.rb
@@ -534,26 +534,28 @@ def render(context)
all_categores = JSON.parse(category_ids.body)
puts "Get doc id numbers from category"
-# category = m.folder_documents(@category, 1, 10000) # max of 10000 items, should get max from all_categories[]['size']
- category = m.folder_documents("56626111",1, 10)
+ category = m.folder_documents(@category, 1, 10000) # max of 10000 items, should get max from all_categories[]['size']
+# category = m.folder_documents("56626111",1, 10)
- puts "Extract the document ids"
- doc_ids = JSON.parse(category.body)["document_ids"]
- ## GOODNESS GRACIOUS, Mendeley forces us to make an API call for EACH DOCUMENT IN THE LIBRARY
- library = Array.new
- doc_ids.each do |article|
- docs = m.library_doc_details(article)
- library << JSON.parse(docs.body)
- end
-
-
- ## Sort everything in the library by date added
- library = library.sort_by { |k| k["date_added"] }
-
- puts "Library created " + library.length.to_s
-
- puts "count is" + @count.to_s + " is of class " + @count.class.to_s
+ if !File.exist?("library.json")
+ doc_ids = JSON.parse(category.body)["document_ids"]
+ ## GOODNESS GRACIOUS, Mendeley forces us to make an API call for EACH DOCUMENT IN THE LIBRARY
+ library = Array.new
+ doc_ids.each do |article|
+ docs = m.library_doc_details(article)
+ library << JSON.parse(docs.body)
+ end
+ ## Sort everything in the library by date added
+ library = library.sort_by { |k| k["date_added"] }
+ # Write out
+ File.open("library.json","w") do |f|
+ f.write(JSON.pretty_generate(library))
+ end
+ else
+ buffer = open('library.json')
+ library = JSON.load(buffer)
+ end
## Generate the output
out = "<ul>" + "\n"

0 comments on commit 859af52

Please sign in to comment.
Something went wrong with that request. Please try again.