This repository has been archived by the owner on Nov 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bibtex fetch and output to file using 'extract-bib'
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'net/http' | ||
|
||
require_relative 'abstract_view' | ||
require_relative '../language' | ||
|
||
module PdfExtract | ||
class BibView < AbstractView | ||
|
||
def render options={} | ||
|
||
bibs = [] | ||
|
||
objects.each_pair do |type, objs| | ||
objs.each do |obj| | ||
|
||
if obj.key? :doi and obj.key? :score | ||
|
||
if obj[:score] > 1 | ||
url = "http://api.crossref.org/works/#{obj[:doi]}/transform/application/x-bibtex" | ||
begin | ||
bib = open(URI.encode(url)).read() | ||
rescue URI::InvalidURIError | ||
puts "DOI not a valid URL: #{obj[:doi]}" | ||
rescue OpenURI::HTTPError | ||
puts "DOI not found on CrossRef: #{obj[:doi]}" | ||
else | ||
puts "Found BibTeX from DOI: #{obj[:doi]}" | ||
bibs << bib | ||
end | ||
end | ||
|
||
else | ||
raise "Must run extract-bib with --resolved_references flag" | ||
end | ||
end | ||
end | ||
|
||
bibs.join("\n") | ||
end | ||
|
||
def self.write render, filename | ||
File.open filename, "w" do |file| | ||
file.write render | ||
end | ||
end | ||
|
||
end | ||
end |