2010-02-09 02:10:17 +01:00
|
|
|
#!/bin/env python
|
2010-02-09 02:45:56 +01:00
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Copyright 2009, 2010 ryuslash
|
|
|
|
#
|
|
|
|
# This file is part of 4grab.
|
|
|
|
#
|
|
|
|
# 4grab is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 4grab is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with 4grab. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
######################################################################
|
|
|
|
|
2010-02-09 01:32:42 +01:00
|
|
|
import optparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import config
|
2010-02-09 02:10:17 +01:00
|
|
|
import download
|
2010-02-09 01:32:42 +01:00
|
|
|
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
|
2010-02-09 02:45:56 +01:00
|
|
|
parser.set_usage(
|
|
|
|
"""%prog [options]
|
|
|
|
|
|
|
|
4grab Copyright (C) 2009-2010 ryuslash
|
|
|
|
This program comes with ABSOLUTELY NO WARRANTY.
|
|
|
|
This is free software, and you are welcome to redistribute it
|
|
|
|
under certain conditions.""")
|
|
|
|
parser.add_option("-e", nargs=2, dest="confval", metavar="CONF VALUE", help="Set configuration option CONF to be VALUE")
|
2010-02-11 21:20:16 +01:00
|
|
|
parser.add_option("-c", "--category", dest="tempcat", metavar="CATEGORY", help="Set the category to CATEGORY only for this run")
|
2010-02-09 01:32:42 +01:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2010-02-11 21:20:16 +01:00
|
|
|
if options.confval and options.tempcat:
|
|
|
|
print "Cannot set a value and download"
|
|
|
|
exit(1)
|
|
|
|
|
2010-02-09 01:32:42 +01:00
|
|
|
if options.confval:
|
|
|
|
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])
|
|
|
|
exit(1)
|
|
|
|
print "Setting", options.confval[0], "to", options.confval[1]
|
2010-02-09 02:10:17 +01:00
|
|
|
config.Configuration().set_option(options.confval[0], options.confval[1])
|
|
|
|
config.Configuration().save()
|
|
|
|
exit(0)
|
2010-02-11 21:20:16 +01:00
|
|
|
elif options.tempcat:
|
|
|
|
config.Configuration().set_category(options.tempcat)
|
2010-02-09 02:10:17 +01:00
|
|
|
|
|
|
|
base_url = "http://boards.4chan.org/%s/" % (config.Configuration().get_category())
|
|
|
|
|
|
|
|
t = download.get_thread_links(base_url)
|
|
|
|
t = download.get_image_links(base_url, t)
|
|
|
|
download.get_images(t)
|