|
|
@ -4,17 +4,17 @@ import os |
|
|
|
file_name = "/var/www/html/index.html" |
|
|
|
file_name = "/var/www/html/index.html" |
|
|
|
|
|
|
|
|
|
|
|
#if the file doesn't exist, we should copy the template to the folder |
|
|
|
#if the file doesn't exist, we should copy the template to the folder |
|
|
|
if not os.exists(file_name): |
|
|
|
if not os.path.exists(file_name): |
|
|
|
template_name = "index.html" |
|
|
|
template_name = "index.html" |
|
|
|
shutil.copy(template_name, file_name) |
|
|
|
shutil.copy(template_name, file_name) |
|
|
|
print("The index file was not available, so we've restored it from template.") |
|
|
|
print("The index file was not available, so we've restored it from template.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Generate a fortune! |
|
|
|
fortune = os.popen("/usr/games/fortune | /usr/games/cowsay").read() |
|
|
|
fortune = os.popen("/usr/games/fortune | /usr/games/cowsay").read() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Write the fortune to the webpage! |
|
|
|
soup = None |
|
|
|
soup = None |
|
|
|
|
|
|
|
|
|
|
|
print("The emergency fortune system has set the fortune to {}".format(fortune)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(file_name, "r") as the_file: |
|
|
|
with open(file_name, "r") as the_file: |
|
|
|
soup = BeautifulSoup(the_file, features="html.parser") |
|
|
|
soup = BeautifulSoup(the_file, features="html.parser") |
|
|
|
|
|
|
|
|
|
|
@ -24,3 +24,5 @@ with open(file_name, "r") as the_file: |
|
|
|
|
|
|
|
|
|
|
|
with open(file_name, "w") as the_file: |
|
|
|
with open(file_name, "w") as the_file: |
|
|
|
the_file.write(str(soup)) |
|
|
|
the_file.write(str(soup)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("The emergency fortune system has set the fortune to {}".format(fortune)) |
|
|
|