summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ryuslash2010-01-18 20:08:38 +0100
committerGravatar ryuslash2010-01-18 20:08:38 +0100
commitc73778910508d43a247feb868f870ad408c4d360 (patch)
treee2312e9e40637441b45e1e61d042ec0781441603
parent4a10e87d3d1cf3e11c03a628823d90b8433490cf (diff)
download4grab-c73778910508d43a247feb868f870ad408c4d360.tar.gz
4grab-c73778910508d43a247feb868f870ad408c4d360.zip
Started working on configuration file
-rw-r--r--config.py36
-rw-r--r--download.py5
2 files changed, 39 insertions, 2 deletions
diff --git a/config.py b/config.py
new file mode 100644
index 0000000..7810458
--- /dev/null
+++ b/config.py
@@ -0,0 +1,36 @@
+import os
+import ConfigParser
+
+class _Configuration(object):
+ def __init__(self):
+ self.filename = os.path.join(os.path.join(os.getenv("HOME"), ".4grab"), "config.cfg")
+ self.configparser = ConfigParser.RawConfigParser()
+ if not os.path.exists(self.filename):
+ self.create_new()
+ else:
+ self.configparser.read(self.filename)
+
+ def create_new(self):
+ self.configparser.add_section("settings")
+ self.configparser.set("settings", "category", self.raw_input_with_default("w", "Please enter which category you would like to download from: "))
+
+ self.configparser.add_section("locations")
+ self.configparser.set("locations", "download", self.raw_input_with_default(os.path.join(os.getenv("HOME"), "Pictures"), "Please enter where you would like the downloads to go: "))
+
+ with open(self.filename) as configfile:
+ self.configparser.write(configfile)
+
+ def raw_input_with_default(self, default, prompt):
+ inp = raw_input("%s (default=%s): " % (prompt, default))
+ if inp == "":
+ return default
+ return inp
+
+ def get_download_location(self):
+ return self.configparser.get("locations", "download")
+
+ def get_category(self):
+ return self.configparser.get("settings", "category")
+
+_configuration = _Configuration()
+def Configuration(): return _configuration
diff --git a/download.py b/download.py
index 4783ced..28b316e 100644
--- a/download.py
+++ b/download.py
@@ -3,8 +3,9 @@ import urllib
import os
import htmlparser
import progressbar
+import config
-savedir = "/home/slash/Pictures/4grab/"
+savedir = Configuration().get_download_location()
def get_thread_links(baseurl):
myparser = htmlparser.MyParser()
@@ -88,7 +89,7 @@ def get_images(t = []):
if __name__ == "__main__":
# Get a file-like object for the 4chan.org w/imgboard
- base_url = "http://boards.4chan.org/w/"
+ base_url = "http://boards.4chan.org/" + Configuration().get_category() + "/"
# Get the hyperlinks.
t = get_thread_links(base_url)