Add `arrived` attribute (file creation timestamp) to books table.
[quanlib.git] / main.rb
1 require 'navigator'
2 require 'page'
3 require 'store'
4 require 'walkdir'
5
6 @outputDir = 'output'
7
8 book_ids = []
9 @config_file = 'quanlib.ini'
10 @skip_class = false
11
12 def handleArg(arg)
13   if arg.start_with?("--config=")
14     @config_file = arg[9..-1]
15     puts 'Using config file "' + @config_file + '".'
16   elsif "--purge" == arg
17     puts 'Purging database...'
18     @store.dropSchema()
19     if File.exists?(@store.unclassified_csv)
20       File.delete(@store.unclassified_csv)
21     end
22   elsif "--skip-class" == arg
23     puts 'Skipping load of classification table.'
24     @skip_class = true
25   elsif arg.start_with?("--")
26     abort('ERROR:  Unrecognized option "' + arg + '".')
27   end
28 end
29
30 @store = Store.new(@config_file)
31 @store.connect()
32
33 for arg in ARGV
34   handleArg(arg)
35 end
36
37 @store.init_db(@skip_class)
38
39 for arg in ARGV
40   if ! arg.start_with?("--")
41     puts 'Scanning directory "' + arg + '"...'
42     w = WalkDir.new(@store, arg)
43     book_ids += (w.books)
44   end
45 end
46
47 puts 'Creating output...'
48
49 navigator = Navigator.new(@store)
50 navigator.write_atoz_pages()
51 navigator.write_series_listing()
52 navigator.write_dewey()
53
54 @store.disconnect()
55