populate the landing page with a few pieces of info

This commit is contained in:
Shoofle 2025-12-11 16:51:03 -05:00
parent dce9e16bf2
commit 9f2aed901d
2 changed files with 23 additions and 4 deletions

View File

@ -19,5 +19,9 @@ font-family: Tahoma, Verdana, Arial, sans-serif; }
<p>The following fortune is taken from the unix fortune file and should not be considered legally binding. At some point soon I'll curate them to only have ones that I would be comfortable popping up at random to our house.</p>
<pre id="fortune-container">fortune goes here</pre>
<pre id="drive-usage-container">drive usage goes here</pre>
<p>this page generated at <code id="time-stamp">time goes here</code></p>
</body>
</html>

View File

@ -1,3 +1,4 @@
import datetime
from bs4 import BeautifulSoup
import os
@ -9,20 +10,34 @@ if not os.path.exists(file_name):
shutil.copy(template_name, file_name)
print("The index file was not available, so we've restored it from template.")
# Generate a fortune!
# Generate some data for the landing page!!
fortune = os.popen("/usr/games/fortune | /usr/games/cowsay").read()
# Write the fortune to the webpage!
drives_we_want = {"/dev/sda5", "Gliese 180 a", "Gliese 180 b", "55 CANCRI B"}
df_output = os.popen("/usr/bin/df -h").read()
df_output = [x for x in df_output.splitlines() if any(drive in x for drive in drives_we_want)]
for x in df_output: print(x)
the_time = datetime.datetime.now()
# Write the stuff to the webpage!
soup = None
with open(file_name, "r") as the_file:
soup = BeautifulSoup(the_file, features="html.parser")
fortune_holder = soup.find(id="fortune-container")
fortune_holder.string = fortune
drive_usage_holder = soup.find(id="drive-usage-container")
drive_usage_holder.string = "\n".join(df_output)
time_holder = soup.find(id="time-stamp")
time_holder.string = str(the_time)
with open(file_name, "w") as the_file:
the_file.write(str(soup))
print("The emergency fortune system has set the fortune to {}".format(fortune))
print()
print("The emergency fortune system has set the fortune to")
print(fortune)