Expand ~ in source dir path
This commit is contained in:
parent
e20ac0b62e
commit
bc0ee53d88
3 changed files with 7 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
imgdir = "."
|
imgdir = "."
|
||||||
refresh = 5
|
refresh = 5
|
||||||
cachedir = ".webslider"
|
cachedir = "/tmp/webslider"
|
||||||
|
resolution = (1920, 1080)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
Flask==1.0.2
|
Flask==1.0.2
|
||||||
Pillow==5.3.0
|
Pillow==5.3.0
|
||||||
|
Click==7.0
|
||||||
|
|
|
@ -13,7 +13,8 @@ import config
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
cache_resolution = (1920, 1080)
|
imgdir = Path(config.imgdir).expanduser().resolve()
|
||||||
|
cache_resolution = config.resolution
|
||||||
cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution)
|
cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution)
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +26,6 @@ def random():
|
||||||
@app.route("/random_image/")
|
@app.route("/random_image/")
|
||||||
def random_image():
|
def random_image():
|
||||||
img_glob = "*jpg"
|
img_glob = "*jpg"
|
||||||
imgdir = Path(config.imgdir)
|
|
||||||
last_modified_time, last_modified_file = max(
|
last_modified_time, last_modified_file = max(
|
||||||
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
||||||
)
|
)
|
||||||
|
@ -64,7 +64,7 @@ def create_cache_file(filename):
|
||||||
|
|
||||||
if not (cache_dir / cache_file).exists():
|
if not (cache_dir / cache_file).exists():
|
||||||
print("Creating cache file", filename)
|
print("Creating cache file", filename)
|
||||||
img = Image.open(Path(config.imgdir) / filename)
|
img = Image.open(imgdir / filename)
|
||||||
img.thumbnail(cache_resolution)
|
img.thumbnail(cache_resolution)
|
||||||
img.save(cache_dir / cache_file, "JPEG")
|
img.save(cache_dir / cache_file, "JPEG")
|
||||||
|
|
||||||
|
@ -72,12 +72,11 @@ def create_cache_file(filename):
|
||||||
|
|
||||||
|
|
||||||
def get_cache_filename(filename):
|
def get_cache_filename(filename):
|
||||||
original_file_path = Path(config.imgdir) / filename
|
original_file_path = imgdir / filename
|
||||||
return sha256(str(original_file_path.resolve()).encode("utf-8")).hexdigest()
|
return sha256(str(original_file_path.resolve()).encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def pre_cache_images():
|
def pre_cache_images():
|
||||||
imgdir = Path(config.imgdir)
|
|
||||||
for image_file in sorted(imgdir.glob("*.jpg")):
|
for image_file in sorted(imgdir.glob("*.jpg")):
|
||||||
create_cache_file(image_file.relative_to(imgdir))
|
create_cache_file(image_file.relative_to(imgdir))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue