Browse Source

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

master
manetta 5 years ago
parent
commit
353f5a0acc
  1. 17
      stream/stream.py

17
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

Loading…
Cancel
Save