|
|
|
#!/bin/python3
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import socket
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
import make_a_gif
|
|
|
|
make_a_gif.make_it()
|
|
|
|
|
|
|
|
# figgure out our local ip address
|
|
|
|
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
s.connect(("8.8.8.8", 80))
|
|
|
|
ip_address = s.getsockname()[0]
|
|
|
|
s.close()
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
soup.find(id="ip_address").string = ip_address
|
|
|
|
|
|
|
|
with open(index_filename, "w") as the_file:
|
|
|
|
the_file.write(str(soup))
|