Dolda2000 GitWeb
/
automanga.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
30053c2
)
Made the htcache more overrideable.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 12 May 2013 04:23:15 +0000
(06:23 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 12 May 2013 04:23:15 +0000
(06:23 +0200)
manga/htcache.py
patch
|
blob
|
blame
|
history
diff --git
a/manga/htcache.py
b/manga/htcache.py
index
6854620
..
2f71f9a
100644
(file)
--- a/
manga/htcache.py
+++ b/
manga/htcache.py
@@
-10,17
+10,20
@@
class cache(object):
n.update(url)
return n.hexdigest()
n.update(url)
return n.hexdigest()
+ def miss(self, url):
+ s = urllib.urlopen(url)
+ try:
+ return s.read()
+ finally:
+ s.close()
+
def fetch(self, url, expire = 3600):
path = pj(self.dir, self.mangle(url))
if os.path.exists(path):
if time.time() - os.stat(path).st_mtime < expire:
with open(path) as f:
return f.read()
def fetch(self, url, expire = 3600):
path = pj(self.dir, self.mangle(url))
if os.path.exists(path):
if time.time() - os.stat(path).st_mtime < expire:
with open(path) as f:
return f.read()
- s = urllib.urlopen(url)
- try:
- data = s.read()
- finally:
- s.close()
+ data = self.miss(url)
if not os.path.isdir(self.dir):
os.makedirs(self.dir)
with open(path, "w") as f:
if not os.path.isdir(self.dir):
os.makedirs(self.dir)
with open(path, "w") as f: