From 7fa3eaa34b7d874455df68ad3ae721b34ba01284 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 27 Nov 2015 08:46:14 -0500 Subject: [PATCH] contrib/benitlux_daily: add verbose option for debug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/benitlux/src/benitlux_daily.nit | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/contrib/benitlux/src/benitlux_daily.nit b/contrib/benitlux/src/benitlux_daily.nit index d242751..492f6a2 100644 --- a/contrib/benitlux/src/benitlux_daily.nit +++ b/contrib/benitlux/src/benitlux_daily.nit @@ -89,9 +89,19 @@ class Benitlux # Get the web page var body = download_html_page + if opts.verbose.value > 1 then + print " # Body" + print body + end + # Parse the Web page and get the available beers var beers = parse_beers_from_html(body) + if opts.verbose.value > 0 then + print " # Beers" + print beers + end + var db = new DB.open(db_path) # Update the database with the beers of the day @@ -112,6 +122,10 @@ class Benitlux # Set the email if desired if send_emails then var subs = db.subscribers + if opts.verbose.value > 0 then + print " # Subscribers" + print subs + end send_emails_to subs end @@ -152,6 +166,11 @@ class Benitlux var of_interest = body.substring(start, finish-start) var lines = of_interest.strip_tags.to_clean_lines + if opts.verbose.value > 0 then + print " # Lines" + print lines + end + var beers = new HashSet[Beer] for line in lines do var parts = line.split(" - ") @@ -202,16 +221,23 @@ redef class OptionContext # Shall we mail the mailing list? var send_emails = new OptionBool("Send emails to subscribers", "-e", "--email") + # Display more debug messages + var verbose = new OptionCount("Display extra debug messages", "-v") + # Print the usage message var help = new OptionBool("Print this help message", "-h", "--help") - redef init do add_option(send_emails, help) + redef init do add_option(send_emails, verbose, help) +end + +redef class Sys + # Command line options + var opts = new OptionContext end # Avoid executing when running tests if "NIT_TESTING".environ == "true" then exit 0 -var opts = new OptionContext opts.parse args if not opts.errors.is_empty or opts.help.value == true then print opts.errors.join("\n") -- 1.7.9.5