and do not fail for new files
This commit is contained in:
parent
cf955e4e9f
commit
963d95ec0d
1 changed files with 17 additions and 18 deletions
|
@ -22,16 +22,15 @@ def read_url(url):
|
||||||
cache_file = "%sindex.html" % cache_file
|
cache_file = "%sindex.html" % cache_file
|
||||||
if os.path.isdir(cache_file):
|
if os.path.isdir(cache_file):
|
||||||
cache_file = os.path.join(cache_file, "index.html")
|
cache_file = os.path.join(cache_file, "index.html")
|
||||||
|
if os.path.exists(cache_file):
|
||||||
ctime = os.stat(cache_file).st_ctime
|
ctime = os.stat(cache_file).st_ctime
|
||||||
now = time.mktime(time.localtime())
|
now = time.mktime(time.localtime())
|
||||||
file_age = now-ctime
|
file_age = now-ctime
|
||||||
print cache_timeout-file_age
|
if file_age < cache_timeout:
|
||||||
if file_age < cache_timeout and os.path.exists(cache_file):
|
|
||||||
f = open(cache_file)
|
f = open(cache_file)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
return data
|
return data
|
||||||
else:
|
|
||||||
data = utils.read_url(url)
|
data = utils.read_url(url)
|
||||||
folder = os.path.dirname(cache_file)
|
folder = os.path.dirname(cache_file)
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
|
|
Loading…
Reference in a new issue