@@ -89,9 +89,19 @@ class Benitlux
89
89
# Get the web page
90
90
var body = download_html_page
91
91
92
+ if opts .verbose .value > 1 then
93
+ print " # Body "
94
+ print body
95
+ end
96
+
92
97
# Parse the Web page and get the available beers
93
98
var beers = parse_beers_from_html (body )
94
99
100
+ if opts .verbose .value > 0 then
101
+ print " # Beers "
102
+ print beers
103
+ end
104
+
95
105
var db = new DB .open (db_path )
96
106
97
107
# Update the database with the beers of the day
@@ -112,6 +122,10 @@ class Benitlux
112
122
# Set the email if desired
113
123
if send_emails then
114
124
var subs = db .subscribers
125
+ if opts .verbose .value > 0 then
126
+ print " # Subscribers "
127
+ print subs
128
+ end
115
129
send_emails_to subs
116
130
end
117
131
@@ -152,9 +166,14 @@ class Benitlux
152
166
var of_interest = body .substring (start , finish -start )
153
167
var lines = of_interest .strip_tags .to_clean_lines
154
168
169
+ if opts .verbose .value > 0 then
170
+ print " # Lines "
171
+ print lines
172
+ end
173
+
155
174
var beers = new HashSet [Beer ]
156
175
for line in lines do
157
- var parts = line .split (" - " )
176
+ var parts = line .split ("- " )
158
177
if parts .length >= 2 then
159
178
beers .add new Beer (parts [0 ].trim , parts [1 ].trim )
160
179
end
@@ -202,16 +221,23 @@ redef class OptionContext
202
221
# Shall we mail the mailing list?
203
222
var send_emails = new OptionBool ("Send emails to subscribers " , "-e " , "--email " )
204
223
224
+ # Display more debug messages
225
+ var verbose = new OptionCount ("Display extra debug messages " , "-v " )
226
+
205
227
# Print the usage message
206
228
var help = new OptionBool ("Print this help message " , "-h " , "--help " )
207
229
208
- redef init do add_option (send_emails , help )
230
+ redef init do add_option (send_emails , verbose , help )
231
+ end
232
+
233
+ redef class Sys
234
+ # Command line options
235
+ var opts = new OptionContext
209
236
end
210
237
211
238
# Avoid executing when running tests
212
239
if "NIT_TESTING " . environ == "true " then exit 0
213
240
214
- var opts = new OptionContext
215
241
opts .parse args
216
242
if not opts .errors .is_empty or opts .help .value == true then
217
243
print opts .errors .join ("\n " )
0 commit comments