"""This module will check to see if craigsimon.guru is up or down.
This module can be run on it's own, or it can be imported into
other code as needed. Regardless, it will allow the underlying code
to determine if craigsimon.guru is up or not. If the site is up, it
will log that fact and returm true. If craigsimon.guru is NOT up then
the code will return False.
examples.
Typical usage example:
foo = ClassFoo()
bar = foo.FunctionBar()
Welcome to the new and inproved craigsimon.guru.
I hope that you find something interesting here for you.
If you would like to reach out, comment on any posting,
or use the contact form.
Thank you.
Craig
"""
import requests
import logging
logger = logging.getLogger('hello_world')
logger.setLevel(logging.DEBUG)
sh = logging.StreamHandler()
sh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
sh.setFormatter(formatter)
logger.addHandler(sh)
def check_craigsimon_guru() -> bool:
request = requests.get('https://www.google.com')
if request.status_code == 200:
logger.info('Hello World!, the site craigsimon.guru is up!')
logger.info('Make sure to stop by for updates to the site!')
return True
else:
logger.debug("This shouldn't happen, the site is in fact up, check your connection!")
return False
if __name__ == "__main__":
logger.info('starting hello_world.py on my website craigsimon.guru')
is_craigsimon_guru_up = check_craigsimon_guru()
if is_craigsimon_guru_up:
logger.debug("Of course it is, it's a static site running on S3.")
else:
logger.critical("Oops S3 is down, time to buy more MREs")
(requests) ➜ hello_world git:(main) ✗ python hello_world.py
2024-03-27 18:45:48,149 - hello_world - INFO - starting hello_world.py on my website craigsimon.guru
2024-03-27 18:45:48,273 - hello_world - INFO - Hello World!, the site craigsimon.guru is up!
2024-03-27 18:45:48,273 - hello_world - INFO - Make sure to stop by for updates to the site!
2024-03-27 18:45:48,274 - hello_world - DEBUG - Of course it is, it's a static site running on S3.
Well that confirms it, craigsimon.guru is up!