varia.website/plugins-custom/stream/stream.py

32 lines
829 B
Python
Raw Normal View History

2021-01-19 22:33:28 +01:00
import time
from datetime import datetime
2021-01-19 22:36:20 +01:00
from os import listdir, path
from pelican import signals
2021-01-19 22:33:28 +01:00
def getCreationTime(img):
creationtime = time.ctime(path.getctime(img))
2021-01-19 22:36:20 +01:00
date = datetime(creationtime).strftime("%y%m%d")
print("creationtime", date)
2021-01-19 22:33:28 +01:00
return date
2021-01-19 22:36:20 +01:00
2021-01-19 22:33:28 +01:00
def getStream(generator):
for page in generator.pages:
dir = "/var/www/stream"
if path.exists(dir):
2021-01-19 22:36:20 +01:00
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)
2021-01-19 22:33:28 +01:00
page.stream = images
2021-01-19 22:36:20 +01:00
2021-01-19 22:33:28 +01:00
def register():
signals.page_generator_finalized.connect(getStream)