diff --git a/flatisfy/config.py b/flatisfy/config.py index ecce0b0..e9c01ac 100644 --- a/flatisfy/config.py +++ b/flatisfy/config.py @@ -277,6 +277,7 @@ def load_config(args=None, check_with_data=True): LOGGER.info("Creating data directory according to config: %s", config_data["data_directory"]) os.makedirs(config_data["data_directory"]) + os.makedirs(os.path.join(config_data["data_directory"], "images")) if config_data["database"] is None: config_data["database"] = "sqlite:///" + os.path.join( diff --git a/flatisfy/filters/cache.py b/flatisfy/filters/cache.py index 229d5f1..6d5de6d 100644 --- a/flatisfy/filters/cache.py +++ b/flatisfy/filters/cache.py @@ -86,7 +86,14 @@ class ImageCache(MemoryCache): """ @staticmethod def compute_filename(url): - return hashlib.sha1(url.encode("utf-8")).hexdigest() + """ + Compute filename (hash of the URL) for the cached image. + + :param url: The URL of the image. + :return: The filename, with its extension. + """ + # Always store as JPEG + return "%s.jpg" % hashlib.sha1(url.encode("utf-8")).hexdigest() def on_miss(self, url): """ diff --git a/flatisfy/filters/images.py b/flatisfy/filters/images.py index 9c21ca8..022f537 100644 --- a/flatisfy/filters/images.py +++ b/flatisfy/filters/images.py @@ -17,7 +17,10 @@ LOGGER = logging.getLogger(__name__) def download_images(flats_list, config): """ - TODO + Download images for all flats in the list, to serve them locally. + + :param flats_list: A list of flats dicts. + :param config: A config dict. """ photo_cache = ImageCache( storage_dir=os.path.join(config["data_directory"], "images")