-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
101 lines (85 loc) · 2.68 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'optparse'
require 'serrano'
require 'bibtex'
require 'fileutils'
load 'tools/parse_bib.rb'
load 'tools/convert.rb'
load 'tools/populate_lib.rb'
load 'tools/populate_stylo.rb'
def run(options)
#Populate.initialize()
if options[:file].include? ".rtf"
puts "Detected RTF file!"
puts "Converting to MD..."
Converter.convert(options)
extension = ".md"
end
if options[:file].include? ".md"
puts "Detected MD file!"
puts "Linting..." #TODO: Add linting
@file = options[:file]
Converter.lint("#{@file}")
extension = ""
end
if ! options[:skipbib]
puts "Parsing bibliography..."
BibParser.run("#{options[:file]}#{extension}")
end
#puts "Populating Zotero library..."
#ZoteroCourier.populate_lib("#{options[:file]}#{extension}.bib")
puts "Received ID : #{options[:id]}"
if options[:id] != ""
id = options[:id]
puts "Populating Stylo with ID = #{options[:id]}"
StyloCourier.populate("#{options[:file]}#{extension}", "#{options[:id]}")
else
puts "Populating Stylo without ID..."
StyloCourier.populate("#{options[:file]}#{extension}", nil)
end
puts "Complete!"
end
def get_bib(file)
return BibParser.run(file)
end
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: app.rb [options]"
opts.on("-i", "--id ID", String, "Include article ID") do |id|
options[:id] = id
end
opts.on("-s", "--skip-bib [FLAG]", "Skip bibliography") do |s|
options[:skipbib] = s.nil? ? false : s
end
opts.on("-f", "--file FILE", "File to parse") do |file|
options[:file] = file
puts "RUNNING RTFTOMD: FILE PARSER"
end
opts.on("-b", "--bib FILE", "MD file to parse bibliography") do |file|
options[:file] = file
get_bib(file)
end
opts.on("-r", "--ref REF", "Reference to search") do |ref|
options[:ref] = ref
puts BibParser.get_ref(ref)
end
opts.on("-l", "--lint FILE", "Lint the file") do |file|
options[:file] = file
Converter.lint(options[:file])
puts "Linting complete"
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end.parse!
if options[:file] == nil
puts "Error: No file specified"
exit
else
run(options)
end
# title = "force"
# author = "derrida"
# res = Serrano.works(query: title, query_author: author)
# # res['message']['items'].collect { |x| x['author'][0]['family'] }
# puts res['message']['items'].collect { |x| x['author'][0]['family'] }