#!/bin/python3 import os import shutil from bs4 import BeautifulSoup index_filename = "/var/www/html/index.html" # If the index is not present in /var/www/html, then we should restore it from the copy we've got. if not os.path.exists(index_filename): shutil.copy("index.html", index_filename) print("The index was lost, so we've restored it.") # take a picture into the stills folder filename = "/stills/" + os.popen("date +%+4Y-%m-%d-%Hh%Mm.jpg").read().strip() os.system("libcamera-jpeg -o /var/www/html" + filename) #make sure that the index shows the latest one soup = None with open(index_filename, "r") as the_file: soup = BeautifulSoup(the_file, features="html.parser") latest_image = soup.find(id="latest") latest_image['src'] = filename with open(index_filename, "w") as the_file: the_file.write(str(soup))