KeyboardInterrupt, 80 columns
Keyboard Interruption (CTRL+C) should now be handled gracefully Tried making the 4grab.py file no more than 80 columns wide
This commit is contained in:
parent
b546de2645
commit
caba2811b9
1 changed files with 54 additions and 29 deletions
57
4grab.py
57
4grab.py
|
@ -50,7 +50,8 @@ def walk_with_wizard(baseurl):
|
||||||
thread = inp
|
thread = inp
|
||||||
inp = raw_input("Which category is this thread in? ")
|
inp = raw_input("Which category is this thread in? ")
|
||||||
print wzrd_msg
|
print wzrd_msg
|
||||||
t = downloader.get_image_links("%s%s/res/" % (baseurl, inp), [thread])
|
t = downloader.get_image_links("%s%s/res/" % (baseurl, inp),
|
||||||
|
[thread])
|
||||||
else:
|
else:
|
||||||
inp = raw_input("Which category would you like to download? ")
|
inp = raw_input("Which category would you like to download? ")
|
||||||
config.Configuration().set_category(inp)
|
config.Configuration().set_category(inp)
|
||||||
|
@ -86,57 +87,81 @@ parser.add_option("-t",
|
||||||
"--thread",
|
"--thread",
|
||||||
dest="thread",
|
dest="thread",
|
||||||
metavar="THREAD",
|
metavar="THREAD",
|
||||||
help="Download only THREAD. If THREAD is only an ID, CATEGORY must also be set. Otherwise, no problem :-)")
|
help="Download only THREAD. If THREAD is only an ID, "
|
||||||
|
"CATEGORY must also be set. Otherwise, no problem :-)")
|
||||||
parser.add_option("-w",
|
parser.add_option("-w",
|
||||||
"--wizard",
|
"--wizard",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
dest="wizard",
|
dest="wizard",
|
||||||
help="I'll put on my robe and wizard hat and help you get some of those pictures you like")
|
help="I'll put on my robe and wizard hat and help you "
|
||||||
|
"get some of those pictures you like")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if options.confval and (options.tempcat or options.thread or options.wizard):
|
if options.confval and (options.tempcat
|
||||||
|
or options.thread
|
||||||
|
or options.wizard):
|
||||||
print "Can't configure something and do something else too."
|
print "Can't configure something and do something else too."
|
||||||
exit(1)
|
exit(1)
|
||||||
if options.wizard and (options.tempcat or options.thread or options.confval):
|
if options.wizard and (options.tempcat
|
||||||
|
or options.thread
|
||||||
|
or options.confval):
|
||||||
print "Can't take a walk with the wizard and do something else too."
|
print "Can't take a walk with the wizard and do something else too."
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if options.confval:
|
if options.confval:
|
||||||
if not config.Configuration().option_exists(options.confval[0]):
|
if not config.Configuration().option_exists(options.confval[0]):
|
||||||
print "%s: error: %s is not a valid configuration option" % (sys.argv[0], options.confval[0])
|
print ("%s: error: %s is not a "
|
||||||
|
"valid configuration option") % (sys.argv[0],
|
||||||
|
options.confval[0])
|
||||||
exit(1)
|
exit(1)
|
||||||
print "Setting", options.confval[0], "to", options.confval[1]
|
print "Setting", options.confval[0], "to", options.confval[1]
|
||||||
config.Configuration().set_option(options.confval[0], options.confval[1])
|
config.Configuration().set_option(options.confval[0],
|
||||||
|
options.confval[1])
|
||||||
config.Configuration().save()
|
config.Configuration().save()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
elif options.wizard:
|
elif options.wizard:
|
||||||
|
try:
|
||||||
walk_with_wizard(base_url)
|
walk_with_wizard(base_url)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print
|
||||||
|
print "Alright, no more wizard hat and robe then. Goodbye"
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
elif options.thread:
|
elif options.thread:
|
||||||
|
try:
|
||||||
if options.thread[:7] == "http://":
|
if options.thread[:7] == "http://":
|
||||||
t = downloader.get_image_links("", [options.thread])
|
t = downloader.get_image_links("", [options.thread])
|
||||||
elif options.tempcat:
|
elif options.tempcat:
|
||||||
url = "%s%s/res/" % (base_url, options.tempcat)
|
url = "%s%s/res/" % (base_url, options.tempcat)
|
||||||
t = downloader.get_image_links(url, [options.thread])
|
t = downloader.get_image_links(url, [options.thread])
|
||||||
else:
|
else:
|
||||||
print "if THREAD is not an absolute URL, CATEGORY must also be specified"
|
print ("if THREAD is not an absolute URL, "
|
||||||
|
"CATEGORY must also be specified")
|
||||||
exit(1)
|
exit(1)
|
||||||
(skipped, failed, downloaded, total) = downloader.get_images(t)
|
(skipped, failed, downloaded, total) = downloader.get_images(t)
|
||||||
print "Downloaded: ", downloaded
|
print "Downloaded: ", downloaded
|
||||||
print "Skipped: ", skipped
|
print "Skipped: ", skipped
|
||||||
print "Failed: ", failed
|
print "Failed: ", failed
|
||||||
print "Total: ", total
|
print "Total: ", total
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print
|
||||||
|
print "Goodbye"
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
elif options.tempcat:
|
elif options.tempcat:
|
||||||
config.Configuration().set_category(options.tempcat)
|
config.Configuration().set_category(options.tempcat)
|
||||||
|
|
||||||
base_url = "%s%s/" % (base_url, config.Configuration().get_category())
|
base_url = "%s%s/" % (base_url, config.Configuration().get_category())
|
||||||
|
|
||||||
t = downloader.get_thread_links(base_url)
|
try:
|
||||||
t = downloader.get_image_links(base_url, t)
|
t = downloader.get_thread_links(base_url)
|
||||||
(skipped, failed, downloaded, total) = downloader.get_images(t)
|
t = downloader.get_image_links(base_url, t)
|
||||||
print "Downloaded: ", downloaded
|
(skipped, failed, downloaded, total) = downloader.get_images(t)
|
||||||
print "Skipped: ", skipped
|
print "Downloaded: ", downloaded
|
||||||
print "Failed: ", failed
|
print "Skipped: ", skipped
|
||||||
print "Total: ", total
|
print "Failed: ", failed
|
||||||
|
print "Total: ", total
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print
|
||||||
|
print "So you don't want these images? Fine! I'll stop then."
|
||||||
|
|
Loading…
Reference in a new issue