changed color printing in quarantine-day-counter when no library found
This commit is contained in:
parent
37d0e32fcd
commit
05e86eb369
2 changed files with 27 additions and 8 deletions
|
@ -6,15 +6,15 @@ import socketserver
|
||||||
import logging
|
import logging
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
|
#__name__ = "python-web-server"
|
||||||
|
__version__ = (1, 1, 1)
|
||||||
|
|
||||||
# setting up logging for this script
|
# setting up logging for this script
|
||||||
_level = logging.INFO
|
_level = logging.INFO
|
||||||
_format = "%(asctime)-15s [%(levelname)-8s] %(lineno)d : %(funcName)s : %(message)s"
|
_format = "%(asctime)-15s [%(levelname)-8s] %(lineno)d : %(funcName)s : %(message)s"
|
||||||
logging.basicConfig(format=_format, level=_level)
|
logging.basicConfig(format=_format, level=_level)
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
# Version
|
|
||||||
version = "1.1.1"
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleHandler(http.server.BaseHTTPRequestHandler):
|
class SimpleHandler(http.server.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler):
|
||||||
uri = ""
|
uri = ""
|
||||||
|
|
||||||
message = f"""Hello, {uri}World!
|
message = f"""Hello, {uri}World!
|
||||||
App version: {version}
|
App version: {__version__}
|
||||||
Server version: {self.server_version}
|
Server version: {self.server_version}
|
||||||
Client address: {self.client_address}
|
Client address: {self.client_address}
|
||||||
Path: {self.path}
|
Path: {self.path}
|
||||||
|
@ -69,7 +69,7 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
message = f"""<html><body>
|
message = f"""<html><body>
|
||||||
<h1>Hello, {uri}World!</h1>
|
<h1>Hello, {uri}World!</h1>
|
||||||
<p>App version: <b>{version}</b></p>
|
<p>App version: <b>{__version__}</b></p>
|
||||||
<p>Server version: <b>{self.server_version}</b></p>
|
<p>Server version: <b>{self.server_version}</b></p>
|
||||||
<p>Client address: <b>{self.client_address}</b></p>
|
<p>Client address: <b>{self.client_address}</b></p>
|
||||||
<p>Path: <b>{self.path}</b></p>
|
<p>Path: <b>{self.path}</b></p>
|
||||||
|
@ -89,6 +89,13 @@ class SockHandler(socketserver.BaseRequestHandler):
|
||||||
self.request.sendall(b"Hello, World!\n")
|
self.request.sendall(b"Hello, World!\n")
|
||||||
|
|
||||||
|
|
||||||
|
def _version(ver=__version__):
|
||||||
|
"""
|
||||||
|
Stringify version value
|
||||||
|
"""
|
||||||
|
return f"{ver[0]}.{ver[1]}.{ver[2]}"
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""
|
"""
|
||||||
Parse args
|
Parse args
|
||||||
|
@ -96,6 +103,7 @@ def parse_args():
|
||||||
argp = argparse.ArgumentParser()
|
argp = argparse.ArgumentParser()
|
||||||
argp.add_argument('-i', '--ip-address', default="", help="IP Address to bind the server")
|
argp.add_argument('-i', '--ip-address', default="", help="IP Address to bind the server")
|
||||||
argp.add_argument('-p', '--port', type=int, default=8080, help="Port on which to listen for traffic")
|
argp.add_argument('-p', '--port', type=int, default=8080, help="Port on which to listen for traffic")
|
||||||
|
argp.add_argument('-v', '--version', action='version', version=f"%(prog)s {_version()}", help="Print version")
|
||||||
argp.add_argument('-d', '--debug', help="Run in debug mode")
|
argp.add_argument('-d', '--debug', help="Run in debug mode")
|
||||||
return argp.parse_args()
|
return argp.parse_args()
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,11 @@ went into hiding (quarantine).
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
|
||||||
|
try:
|
||||||
import color
|
import color
|
||||||
|
except:
|
||||||
|
print("Unable to import the color library. No colors for you.")
|
||||||
|
|
||||||
|
|
||||||
quarantine_start_date = "13 Mar 2020"
|
quarantine_start_date = "13 Mar 2020"
|
||||||
|
@ -24,6 +28,13 @@ def quarantine_days(quarantine_start_date=quarantine_start_date):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# args = parse_args()
|
# args = parse_args()
|
||||||
print(f"\nQuarantine Start Date: {color.yellow(quarantine_start_date)}")
|
try:
|
||||||
print(f"Quarantine Days: {color.red(quarantine_days(quarantine_start_date))}")
|
start_date_message = f"\nQuarantine Start Date: {color.yellow(quarantine_start_date)}"
|
||||||
|
quarantine_days_message = f"Quarantine Days: {color.red(quarantine_days(quarantine_start_date))}"
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
start_date_message = f"\nQuarantine Start Date: {quarantine_start_date}"
|
||||||
|
quarantine_days_message = f"Quarantine Days: {quarantine_days(quarantine_start_date)}"
|
||||||
|
|
||||||
|
print(start_date_message)
|
||||||
|
print(quarantine_day_message)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue