瀏覽代碼

Reformatted main.py

Nikola Kotur 3 年之前
父節點
當前提交
f8509c9489
共有 1 個文件被更改,包括 53 次插入44 次删除
  1. 53 44
      main.py

+ 53 - 44
main.py

@@ -7,64 +7,73 @@ from flask_cors import CORS, cross_origin
 
 
 def get_result():
-  services_up = 0
-  failure_list = []
-  returnResponse = {"style":"", "title":"", "content":""}
-  statping_endpoint = os.getenv('STATPING_ENDPOINT')
+    services_up = 0
+    failure_list = []
+    returnResponse = {"style": "", "title": "", "content": ""}
+    statping_endpoint = os.getenv("STATPING_ENDPOINT")
 
-  try:
-    print('%sapi/services/' % statping_endpoint)
-    response = requests.get('%sapi/services/' % statping_endpoint, verify=False)
-      # If we get a response
-    if response.status_code == 200:
-      # Get the total number of services returned
-      total_services = len(response.json())
-      # Iterate through the response
-      for key in response.json():
-        # If the service is online, incrememnt the up count
-        if key["online"] == True:
-          services_up += 1
-        # Otherwise append the name to the naughty list
-        else:
-          failure_list.append(key["name"])
+    try:
+        print("%sapi/services/" % statping_endpoint)
+        response = requests.get("%sapi/services/" % statping_endpoint, verify=False)
+        # If we get a response
+        if response.status_code == 200:
+            # Get the total number of services returned
+            total_services = len(response.json())
+            # Iterate through the response
+            for key in response.json():
+                # If the service is online, incrememnt the up count
+                if key["online"] == True:
+                    services_up += 1
+                # Otherwise append the name to the naughty list
+                else:
+                    failure_list.append(key["name"])
 
-      # Check the number of up services is equal to the total number of services
-      if total_services == services_up:
-        # if so, return a success object
-        returnResponse["style"] = "is-success"
-        returnResponse["title"] = "All good in the hood boss"
-        returnResponse["content"] = "<b>%s / %s Services showing as online. Check <a href=%s target=_blank>here</a> for more info. </br> <p>" % (services_up, total_services, statping_endpoint)
+            # Check the number of up services is equal to the total number of services
+            if total_services == services_up:
+                # if so, return a success object
+                returnResponse["style"] = "is-success"
+                returnResponse["title"] = "All good in the hood boss"
+                returnResponse["content"] = (
+                    "<b>%s / %s Services showing as online. Check <a href=%s target=_blank>here</a> for more info. </br> <p>"
+                    % (services_up, total_services, statping_endpoint)
+                )
 
-        return(returnResponse)
-      else:
-        # return a numpty message
+                return returnResponse
+            else:
+                # return a numpty message
+                returnResponse["style"] = "is-danger"
+                returnResponse["title"] = "Halp"
+                # need to build the return message to include the failures as a formatted list
+                numptyList = "<ul>"
+                for i in failure_list:
+                    numptyList += "<li>" + i + "</li>"
+                numptyList += "</ul>"
+                returnResponse["content"] = (
+                    "<b>%s / %s Services showing as online. Check <a href=%s target=_blank>here</a> for more info. </br> <p> <br>Here are the numpties that are letting the side down:</br> %s"
+                    % (services_up, total_services, numptyList, statping_endpoint)
+                )
+
+                return returnResponse
+
+    except:
         returnResponse["style"] = "is-danger"
-        returnResponse["title"] = "Halp"
-        # need to build the return message to include the failures as a formatted list
-        numptyList = "<ul>"
-        for i in failure_list:
-          numptyList += "<li>" + i + "</li>"
-        numptyList += "</ul>"
-        returnResponse["content"] = "<b>%s / %s Services showing as online. Check <a href=%s target=_blank>here</a> for more info. </br> <p> <br>Here are the numpties that are letting the side down:</br> %s" % (services_up, total_services, numptyList, statping_endpoint)
-      
-        return(returnResponse)
+        returnResponse["title"] = "I have the sads"
+        returnResponse["content"] = "Like, man cannot even holla at Statping."
+
+        return returnResponse
 
-  except:
-    returnResponse["style"] = "is-danger"
-    returnResponse["title"] = "I have the sads"
-    returnResponse["content"] = "Like, man cannot even holla at Statping."
-    
-    return(returnResponse)
 
 app = Flask(__name__)
 app.config["JSON_SORT_KEYS"] = False
 cors = CORS(app)
-app.config['CORS_HEADERS'] = 'Content-Type'
+app.config["CORS_HEADERS"] = "Content-Type"
+
 
 @app.route("/endpoint/", methods=["GET"])
 @cross_origin()
 def welcome():
     return jsonify(get_result())
 
+
 if __name__ == "__main__":
     app.run(host="0.0.0.0", port=8099)