manymanymany-varia-websites/plugins-custom/stream/stream.py

27 lines
807 B
Python
Raw Normal View History

2021-01-19 22:33:28 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from pelican import signals
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"
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
def register():
signals.page_generator_finalized.connect(getStream)