Skip to content

Instantly share code, notes, and snippets.

@MatteoRagni
Created January 18, 2016 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatteoRagni/e0b368ffbf4a0fb67024 to your computer and use it in GitHub Desktop.
Save MatteoRagni/e0b368ffbf4a0fb67024 to your computer and use it in GitHub Desktop.
Searcher for bibliography. Requires scholar.py
#!/usr/bin/env ruby
require 'colorize'
# Comment a paper using %
$PAPERS = <<-ENDOFLIST
ENDOFLIST
$PAPERS = $PAPERS.chomp.split /\n/
bibliography = ""
$PAPERS.each_with_index do |paper, i|
print "[#{i+1} of #{$PAPERS.size}] "
begin
puts "Commented... skipping"
next
end if paper =~ /%+\s.*/
command = "scholar.py -c 1 --phrase \"#{paper}\" --no-patents --no-citations --citation bt"
puts command.red
result = `#{command}`
if result != ""
bibliography += result
puts "INFO: ".blue + paper.white + " saved in bibliography".green
puts result.light_blue
else
puts "WARNING! ".yellow + paper.white + " returned no result".yellow
end
end
puts "Writing to temporary bib file. Remember to check it!"
File.open("bib.bib", "a") do |f|
f.puts bibliography
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment