From 5516dbbcae07b9623565c9dc8f06267b3357366e Mon Sep 17 00:00:00 2001 From: ryuslash Date: Fri, 12 Feb 2010 00:04:34 +0100 Subject: [PATCH] Stopped saying Failed and Skipped things Now it summarizes at the end --- 4grab.py | 18 +++++++++++++++--- download.py | 11 +++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/4grab.py b/4grab.py index c3e2358..ae550b4 100755 --- a/4grab.py +++ b/4grab.py @@ -54,7 +54,11 @@ def walk_with_wizard(baseurl): t = download.get_thread_links(baseurl) t = download.get_image_links(baseurl, t) - download.get_images(t) + (skipped, failed, downloaded, total) = download.get_images(t) + print "Downloaded: ", downloaded + print "Skipped: ", skipped + print "Failed: ", failed + print "Total: ", total parser.set_usage( """%prog [options] @@ -97,7 +101,11 @@ elif options.thread: else: print "if THREAD is not an absolute URL, CATEGORY must also be specified" exit(1) - download.get_images(t) + (skipped, failed, downloaded, total) = download.get_images(t) + print "Downloaded: ", downloaded + print "Skipped: ", skipped + print "Failed: ", failed + print "Total: ", total exit(0) elif options.tempcat: config.Configuration().set_category(options.tempcat) @@ -106,4 +114,8 @@ base_url = "%s%s/" % (base_url, config.Configuration().get_category()) t = download.get_thread_links(base_url) t = download.get_image_links(base_url, t) -download.get_images(t) +(skipped, failed, downloaded, total) = download.get_images(t) +print "Downloaded: ", downloaded +print "Skipped: ", skipped +print "Failed: ", failed +print "Total: ", total diff --git a/download.py b/download.py index 63040c9..b9f9f72 100644 --- a/download.py +++ b/download.py @@ -93,6 +93,9 @@ def get_image_links(baseurl, t = []): return mysubparser.get_hyperlinks() def get_images(t = []): + skipped = 0 + failed = 0 + downloaded = 0 total = len(t) progress = progressbar.Progress(total) i = 1 @@ -107,12 +110,16 @@ def get_images(t = []): break except IOError: tries -= 1 - print "\rDownloading of", link, "failed,", tries, "left" + if tries == 0: + failed += 1 + else: + downloaded += 1 else: - print "\rNot downloading", link, "already downloaded" + skipped += 1 i += 1 progress.complete() + return (skipped, failed, downloaded, total) if __name__ == "__main__": # Get a file-like object for the 4chan.org w/imgboard