Module: IEEEPaperDownloader
- Defined in:
- lib/ieee_paper_downloader.rb,
lib/ieee_paper_downloader/cli.rb,
lib/ieee_paper_downloader/version.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- API_URI =
'http://ieeexploreapi.ieee.org/api/v1/search/articles'.freeze
- API_KEY =
ENV['IEEE_XPLORE_API']
- VERSION =
"0.1.0"
Class Method Summary collapse
- .download(article_number, filename) ⇒ Object
- .read_csv(csv_path) ⇒ Object
- .search(query_text) ⇒ Object
Class Method Details
.download(article_number, filename) ⇒ Object
19 20 21 22 |
# File 'lib/ieee_paper_downloader.rb', line 19 def download(article_number, filename) uri = "http://ieeexplore.ieee.org/stampPDF/getPDF.jsp?tp=&isnumber=&arnumber=#{article_number}" system("echo '#{uri}' | xargs wget -O '#{filename}'") end |
.read_csv(csv_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ieee_paper_downloader.rb', line 24 def read_csv(csv_path) csv_data = CSV.read(csv_path, headers: true) articles = csv_data.map do |record| pdf_link = record.find do |element| element[0].include?('PDF Link') end[1] article_number = Hash[URI.decode_www_form(URI.parse(pdf_link).query)]['arnumber'] title = record.find do |element| element[0].include?('Document Title') end[1].gsub(/\//, ' and ') { 'article_number' => article_number, 'title' => title } end articles end |
.search(query_text) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/ieee_paper_downloader.rb', line 12 def search(query_text) raise "環境変数IEEE_XPLORE_APIがセットされていません" if API_KEY.nil? uri = "#{API_URI}?querytext=#{query_text}&format=json&subscribed=true&apikey=#{API_KEY}" result = JSON.parse(Net::HTTP.get(URI.parse(uri))) result end |