added a fallback for rendering the website locally, where /var/www/stream does not exist

This commit is contained in:
manetta 2019-05-13 22:30:54 +02:00
parent 5364009530
commit 353f5a0acc

View File

@ -2,14 +2,23 @@
# -*- coding: utf-8 -*- # # -*- coding: utf-8 -*- #
from pelican import signals from pelican import signals
from os import listdir from os import listdir, path
from os.path import isfile, join import time
# import os 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): def getStream(generator):
for page in generator.pages: for page in generator.pages:
dir = "/var/www/stream" 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) print('>>> The stream is streaming!', images)
page.stream = images page.stream = images