From 353f5a0acc9d1e09852f94a5b25b8b06b1d4e7ac Mon Sep 17 00:00:00 2001 From: manetta Date: Mon, 13 May 2019 22:30:54 +0200 Subject: [PATCH] added a fallback for rendering the website locally, where /var/www/stream does not exist --- stream/stream.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/stream/stream.py b/stream/stream.py index 74627a8..541a60a 100644 --- a/stream/stream.py +++ b/stream/stream.py @@ -2,14 +2,23 @@ # -*- coding: utf-8 -*- # from pelican import signals -from os import listdir -from os.path import isfile, join -# import os +from os import listdir, path +import time +from datetime import datetime + +def getCreationTime(img): + creationtime = time.ctime(path.getctime(img)) + date = datetime(creationtime).strftime('%y%m%d') + print('creationtime', date) + return date def getStream(generator): for page in generator.pages: dir = "/var/www/stream" - images = [f for f in listdir(dir) if isfile(join(dir, f))] + if path.exists(dir): + images = [(getCreationTime(dir+'/'+f), f) for f in listdir(dir) if path.isfile(path.join(dir, f))] + else: # if the website is generated locally + images = ['placeholder.png'] print('>>> The stream is streaming!', images) page.stream = images