<commit_before>require "resque"
require "rubygems"
require "net/http"
require "json"

class MendeleyDetails
  @queue = :mendeley_details
  
  def self.perform(mendeley_paper)
    @mendeley_paper = MendeleyPaper.find_by_id(mendeley_paper["mendeley_paper"]["id"].to_i)
    
    key_handle = File.open(::Rails.root.to_s+"/key_mendeley.txt")
    api_key = key_handle.readline.rstrip
    
    detail_url = "http://api.mendeley.com/oapi/documents/details/" + @mendeley_paper.uuid + "/?consumer_key="+api_key
    begin
      detail_resp = Net::HTTP.get_response(URI.parse(detail_url))
    rescue
      retry
    end
    
    detail_data = detail_resp.body
    detail_result = JSON.parse(detail_data)
    
    if detail_result["oa_journal"] != false
      @mendeley_paper.open_access = true
    else
      @mendeley_paper.open_access = false
    end
    
    print "mendeley details: updated oa- and reader-status\n"
    @mendeley_paper.reader = detail_result["stats"]["readers"]
    @mendeley_paper.save
  end
end<commit_msg>added delay to mendeley-details to save the API<commit_after>require "resque"
require "rubygems"
require "net/http"
require "json"

class MendeleyDetails
  @queue = :mendeley_details
  
  def self.perform(mendeley_paper)
    @mendeley_paper = MendeleyPaper.find_by_id(mendeley_paper["mendeley_paper"]["id"].to_i)
    
    key_handle = File.open(::Rails.root.to_s+"/key_mendeley.txt")
    api_key = key_handle.readline.rstrip
    
    detail_url = "http://api.mendeley.com/oapi/documents/details/" + @mendeley_paper.uuid + "/?consumer_key="+api_key
    begin
      detail_resp = Net::HTTP.get_response(URI.parse(detail_url))
    rescue
      retry
    end
    
    detail_data = detail_resp.body
    detail_result = JSON.parse(detail_data)
    
    if detail_result["oa_journal"] != false
      @mendeley_paper.open_access = true
    else
      @mendeley_paper.open_access = false
    end
    
    print "mendeley details: updated oa- and reader-status\n"
    @mendeley_paper.reader = detail_result["stats"]["readers"]
    @mendeley_paper.save
    print "-> sleep for 5 secs\n\n"
    sleep(5)
  end
end
{'fraction_non_alphanumeric': 0.11373289287399717, 'fraction_numerical': 0.0009438414346389807, 'mean_word_length': 3.5591397849462365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4523966', 'n_tokens_mistral': 789, 'n_tokens_neox': 768, 'n_words': 122}