def fetch_relative(url, proxies=None, postfetch=None):
"""postfetch is a callback that receives fetched data (as string)"""
path = localize_path(url)
path = normalize_path(path)
if os.path.exists(path):
if postfetch:
logging.debug("reprocessing file %s" % path)
f = open(path, "rb")
data = f.read()
f.close()
postfetch(data)
return False
logging.debug("fetching %s" % url)
f = urllib.urlopen(url, proxies=proxies)
data = f.read()
f.close()
head, tail = os.path.split(path)
if not os.path.exists(head):
os.makedirs(head)
f = open(path, "wb")
f.write(data)
f.close()
if postfetch:
postfetch(data)
return True
评论列表
文章目录