summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ryuslash2010-02-09 02:10:17 +0100
committerGravatar ryuslash2010-02-09 02:10:17 +0100
commit1b09267876e51c0456c062e10ab70c0f7eba6c34 (patch)
tree8afb37f35b3563165aa7a41d32f2120620b5b811
parent91e0b5dc665679e30cfd2114a68adce9af04a3e9 (diff)
download4grab-1b09267876e51c0456c062e10ab70c0f7eba6c34.tar.gz
4grab-1b09267876e51c0456c062e10ab70c0f7eba6c34.zip
configuration settings and startfile
Configuration Settings can now be changed with the -e command line argument execution of 4grab has been moved to 4grab.py, but should also still work with download.py
-rwxr-xr-x[-rw-r--r--]4grab.py12
-rw-r--r--config.py16
-rw-r--r--download.py4
3 files changed, 28 insertions, 4 deletions
diff --git a/4grab.py b/4grab.py
index 4de6526..7863854 100644..100755
--- a/4grab.py
+++ b/4grab.py
@@ -1,7 +1,9 @@
+#!/bin/env python
import optparse
import sys
import config
+import download
parser = optparse.OptionParser()
@@ -14,4 +16,12 @@ if options.confval:
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]
- config.Configuration().
+ config.Configuration().set_option(options.confval[0], options.confval[1])
+ config.Configuration().save()
+ exit(0)
+
+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)
diff --git a/config.py b/config.py
index 06cf0dc..7f448b8 100644
--- a/config.py
+++ b/config.py
@@ -40,11 +40,25 @@ class _Configuration(object):
self.configparser.set("settings", "category", value)
def option_exists(self, option):
- for section in self.configparser.sections():
+ sections = self.configparser.sections()
+ for section in sections:
if self.configparser.has_option(section, option):
return True
return False
+ def set_option(self, option, value):
+ sec = None
+ sections = self.configparser.sections()
+ for section in sections:
+ if self.configparser.has_option(section, option):
+ sec = section
+
+ if not sec is None:
+ self.configparser.set(sec, option, value)
+ return True
+ else:
+ return False
+
def save(self):
dirname = os.path.dirname(self.filename)
if not os.path.exists(dirname):
diff --git a/download.py b/download.py
index 003e718..7ab1a43 100644
--- a/download.py
+++ b/download.py
@@ -19,7 +19,7 @@ def get_thread_links(baseurl):
for pagenum in t:
progress.show_progress(i)
- url = base_url + pagenum
+ url = baseurl + pagenum
tries = 10
while tries > 0:
try:
@@ -49,7 +49,7 @@ def get_image_links(baseurl, t = []):
for link in t:
progress.show_progress(i)
- img_url = base_url + link
+ img_url = baseurl + link
tries = 10
while tries > 0:
try: