d193c22360fab18aa2850cbc5a2b6d132c2aa843
[quanlib.git] / main.rb
1 require 'page'
2 require 'store'
3 require 'walkdir'
4
5 outputDir = 'output'
6
7 book_ids = []
8 imageCount = 0
9
10 def handleArg(arg)
11   if "--purge" == arg
12     puts 'Purging database...'
13     @store.dropSchema()
14   elsif arg.start_with?("--")
15     abort('ERROR:  Unrecognized option "' + arg + '".')
16   end
17 end
18
19 @store = Store.new()
20 @store.connect()
21
22 for arg in ARGV
23   handleArg(arg)
24 end
25
26 @store.init_db()
27
28 for arg in ARGV
29   if ! arg.start_with?("--")
30     puts 'Scanning directory "' + arg + '"...'
31     w = WalkDir.new(@store, arg)
32     book_ids += (w.books)
33   end
34 end
35
36 puts 'Creating output...'
37
38 counts = {}
39
40 ('A'..'Z').each do |letter| 
41   book_ids = @store.query_books_by_author(letter + '%')
42   puts 'Authors starting with "' + letter + '":  ' + book_ids.length.to_s() + ' books.'
43   counts[letter] = book_ids.length
44
45   page = Page.new(@store)
46   if 'A' != letter
47     page.back = ['../output_' + (letter.ord - 1).chr + '/index.html', 'Prev']
48   end
49   if 'Z' != letter
50     page.forward = ['../output_' + (letter.ord + 1).chr + '/index.html', 'Next']
51   end
52   page.output_dir = 'output_' + letter
53   page.title = "Authors starting with '" + letter + "'"
54   page.up = ['../output/index.html', 'Index']
55
56   page.write_html(book_ids)
57 end
58
59 content = '<table><tr><th>Author</th><th>Books</th></tr>'
60 ('A'..'Z').each do |letter|
61   content += '  <tr><td><a href="../output_' + letter + '/index.html">Starting with ' + letter + '</a></td><td>' + counts[letter].to_s + '</td></tr>'
62 end
63 page = Page.new(@store)
64 page.output_dir = 'output'
65 page.special = content
66 page.write_html( [] )
67   
68 @store.disconnect()
69