X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Fhtcache.py;h=2aa594ef710750066c380ef85b5f37c61afb62a0;hb=40277671182cc3dd6ea80346630cc22d03235033;hp=45ede5d8f594da98ff068b63d79bc9b5e3e26ff9;hpb=3cc7937cd91ec6d3cfb7eebcd4c1afd85c5a615a;p=automanga.git diff --git a/manga/htcache.py b/manga/htcache.py index 45ede5d..2aa594e 100644 --- a/manga/htcache.py +++ b/manga/htcache.py @@ -1,4 +1,5 @@ import os, hashlib, urllib.request, time +from . import profile pj = os.path.join class cache(object): @@ -11,7 +12,8 @@ class cache(object): return n.hexdigest() def miss(self, url): - with urllib.request.urlopen(url) as s: + req = urllib.request.Request(url, headers={"User-Agent": "automanga/1"}) + with urllib.request.urlopen(req) as s: if s.headers.get("content-encoding") == "gzip": import gzip, io return gzip.GzipFile(fileobj=io.BytesIO(s.read()), mode="r").read() @@ -30,10 +32,7 @@ class cache(object): f.write(data) return data -home = os.getenv("HOME") -if home is None or not os.path.isdir(home): - raise Exception("Could not find home directory for HTTP caching") -default = cache(pj(home, ".manga", "htcache")) +default = cache(pj(profile.confdir, "htcache")) def fetch(url, expire=3600): return default.fetch(url, expire)