Created
July 6, 2013 15:35
-
-
Save bmiles/5940255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'json' | |
require 'nokogiri' | |
require 'open-uri' | |
# | |
# This is a shart script to get demo content to populate an inial set of 'science gists' | |
# We started by trying to call the elife api directly, but it sucked balls | |
# then we tried to use content negotiation, but that is also flakey | |
# finally we will had insert the path the the XML | |
# pass the full xml to nokogiri | |
# then extract the xml node '<abstract abstract-type="executive-summary"' | |
class Digest | |
attr_accessor :gist, :doi | |
def initialize(doi, gist="no content") | |
@doi = doi | |
@gist = doi2gist() | |
end | |
def doi2gist() | |
strippeddoi = @doi.gsub(/dx.doi.org\//, '') | |
uri = "http://elife.elifesciences.org/elife-source-xml/#{strippeddoi}" | |
puts strippeddoi | |
puts uri | |
elife_raw_xml = open(uri).read | |
digest_xml_path = 'abstract[abstract-type="executive-summary"]' | |
xml = Nokogiri::XML(elife_raw_xml) | |
digest = xml.css(digest_xml_path) | |
digesttext = digest.text | |
return digesttext.gsub(/abstract-2#{strippeddoi}.002eLife digest/, '') | |
end | |
end | |
#test doi1: 'dx.doi.org/10.7554/eLife.00782' | |
#test doi2: 'dx.doi.org/10.7554/eLife.00800' | |
ben = GistGetter::Digest.new('dx.doi.org/10.7554/eLife.00782') | |
puts ben.doi | |
puts ben.gist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment