From 139164b39a307ef741c5335564553e4ce4ebdd87 Mon Sep 17 00:00:00 2001 From: Dithilli <41286037+Dithilli@users.noreply.github.com> Date: Wed, 25 Jul 2018 17:58:17 -0700 Subject: [PATCH 1/3] Rename hiwe.py to hiwe2.py --- hiwe2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hiwe2.py b/hiwe2.py index a586f36..02e00d3 100644 --- a/hiwe2.py +++ b/hiwe2.py @@ -19,9 +19,9 @@ def namer(): name = None if name == None and len(sys.argv) > 1: name = sys.argv[1] - if name == None: + elif name == None: name = os.getenv('HIWENAME') - if name == None: + elif name == None: name = "David" return name From 7b0374bf952fc53eccb029fa34c6b179e6e4fce3 Mon Sep 17 00:00:00 2001 From: Dithilli <41286037+Dithilli@users.noreply.github.com> Date: Wed, 25 Jul 2018 19:05:58 -0700 Subject: [PATCH 2/3] Update hiwe.py --- hiwe.py | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/hiwe.py b/hiwe.py index f095c5b..0128367 100644 --- a/hiwe.py +++ b/hiwe.py @@ -1,28 +1,45 @@ -import os, sys -from datetime import datetime -from bottle import Bottle, route, run, response, request - - -name = None +""" +hiwe2.py is a "hello world" that runs in a Bottle webserver, and responds to a hit on it's only endpoint with "Hello WeWork and greetings from ", where name is either default, or set by the user using an environment variable, or a command line argument. +It also outputs to STDOUT a log that contains the date and time, the endpoint reached, and the http status code. +""" -if name == None: - name = os.getenv('name') -if name == None and len(sys.argv) > 1: - name = sys.argv[1] -if name == None: - name = "David" +import os, sys +from datetime import datetime +from bottle import route, run, response, request + +""" +Function namer first creates the variable name, and then checks to see if there's a command line argument setting name. +If not, it checks for an environment variable that sets the variable 'name'. If not, it sets the default to "David". +Considered using ArgParse for inputting command line arguments, but this just didn't need it. +""" +def namer(): + name = None + if name == None and len(sys.argv) > 1 and sys.argv[1] != None: + name = sys.argv[1] + elif name == None and os.getenv('HIWENAME') != None: + name = os.getenv('HIWENAME') + elif name == None: + name = "David" + return name + +""" +Function logger creates three variables (code, time, and endpoint) and populates them with information pulled from +the datetime module, or from the http response object, or request object +""" +def logger(): + code = str(response.status_code) + time = datetime.now() + printtime = time.strftime("%H:%M:%S") + endpoint = str(request.fullpath) + return printtime + " - Got a request to " + endpoint + " endpoint. Replied with code " + code @route('/') def hi(): - code = str(response.status) - time = str(datetime.now()) - endpoint = str(request.fullpath) - printout = (time + "- Got a request to " + endpoint + "endpoint. Replied with code" + code) - print(printout) - sys.stdout.write(printout) + name = namer() + print(logger()) return "Hello WeWork and greetings from %s!" % name -run(host='localhost', port=8080) +run(host='0.0.0.0', port=8080) From 36de97aa2d4a6f064bade5c9744febc7c9f20209 Mon Sep 17 00:00:00 2001 From: Dithilli <41286037+Dithilli@users.noreply.github.com> Date: Wed, 25 Jul 2018 19:25:14 -0700 Subject: [PATCH 3/3] Delete hiwe2.py --- hiwe2.py | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 hiwe2.py diff --git a/hiwe2.py b/hiwe2.py deleted file mode 100644 index 02e00d3..0000000 --- a/hiwe2.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -hiwe2.py is a "hello world" that runs in a Bottle webserver, and responds to a hit on it's only endpoint with "Hello WeWork and greetings from ", where name is either default, or set by the user using an environment variable, or a command line argument. - -It also outputs to STDOUT a log that contains the date and time, the endpoint reached, and the http status code. -""" - - -import os, sys -from datetime import datetime -from bottle import route, run, response, request - -""" -Function namer first creates the variable name, and then checks to see if there's a command line argument setting name. -If not, it checks for an environment variable that sets the variable 'name'. If not, it sets the default to "David". - -Considered using ArgParse for inputting command line arguments, but this just didn't need it. -""" -def namer(): - name = None - if name == None and len(sys.argv) > 1: - name = sys.argv[1] - elif name == None: - name = os.getenv('HIWENAME') - elif name == None: - name = "David" - return name - -""" -Function logger creates three variables (code, time, and endpoint) and populates them with information pulled from -the datetime module, or from the http response object, or request object -""" -def logger(): - code = str(response.status_code) - time = datetime.now() - printtime = time.strftime("%H:%M:%S") - endpoint = str(request.fullpath) - return printtime + " - Got a request to " + endpoint + " endpoint. Replied with code " + code - -@route('/') -def hi(): - name = namer() - print(logger()) - return "Hello WeWork and greetings from %s!" % name - - - -run(host='localhost', port=8080) -