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))