From d8962c82b00a9aeb0fef8a771d2804e050767748 Mon Sep 17 00:00:00 2001 From: Shoofle Date: Thu, 10 Feb 2022 13:05:53 -0500 Subject: [PATCH] when the update_fortune task runs, it will now copy the template index if it's not present at the folder --- cygnus.service | 1 + update_fortune.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cygnus.service b/cygnus.service index 002a054..df87a7f 100644 --- a/cygnus.service +++ b/cygnus.service @@ -3,6 +3,7 @@ Description=Generate a new fortune for the cygnus landing page. [Service] Type=oneshot +WorkingDirectory = /home/shoofle/cygnus ExecStart=python /home/shoofle/cygnus/update_fortune.py User=shoofle diff --git a/update_fortune.py b/update_fortune.py index 5da4adb..a55550b 100644 --- a/update_fortune.py +++ b/update_fortune.py @@ -1,9 +1,16 @@ from bs4 import BeautifulSoup import os +file_name = "/var/www/html/index.html" + +#if the file doesn't exist, we should copy the template to the folder +if not os.exists(file_name): + template_name = "index.html" + shutil.copy(template_name, file_name) + print("The index file was not available, so we've restored it from template.") + fortune = os.popen("/usr/games/fortune | /usr/games/cowsay").read() -file_name = "/var/www/html/index.html" soup = None print("The emergency fortune system has set the fortune to {}".format(fortune))