Skip to content

Instantly share code, notes, and snippets.

@skoba
Last active November 19, 2018 09:08
Show Gist options
  • Save skoba/95428643cfea23aec2415af76fe4db98 to your computer and use it in GitHub Desktop.
Save skoba/95428643cfea23aec2415af76fe4db98 to your computer and use it in GitHub Desktop.
Converter from researchmap CSV file to BibTeX file. only english paper
#! /usr/bin/env ruby
# coding: utf-8
require 'csv'
csvfile = ARGV[0] || "paper.csv"
bibfile = ARGV[1] || "paper.bib"
csv = CSV.read(csvfile, headers: true, encoding: 'Shift_JIS:UTF-8')
bib = File.open(bibfile, "w", encoding: "UTF-8")
csv.each do |line|
label = line['タイトル(英語)'][0..8].gsub(' ','_') + line['出版年月']
author = line['著者(英語)']
title = line['タイトル(英語)']
journal = line['誌名(英語)']
volume = line['巻']
number = line['号']
startp = line['開始ページ']
endp = line['終了ページ']
year = line['出版年月'][0..3]
article = <<END
@article{#{label},
author = "#{author}",
title = "#{title}",
journal = "#{journal}",
volume = "#{volume}",
number = "#{number}",
pages = "#{startp}--#{endp}",
year = "#{year}"
}
END
bib.puts article
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment