From e2e8be5ab390ececafb9af118b95c9f6f4e59643 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 31 Jan 2017 23:02:01 +0100 Subject: [PATCH] Added uptime to api request and changed returning state to None --- .gitignore | 1 + v1/__pycache__/diskusage.cpython-34.pyc | Bin 920 -> 0 bytes v1/__pycache__/uptime.cpython-34.pyc | Bin 978 -> 972 bytes v1/app.py | 19 ++++++------------- v1/uptime.py | 10 +++++----- 5 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 .gitignore delete mode 100644 v1/__pycache__/diskusage.cpython-34.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54921dc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +v1/__pycache__ diff --git a/v1/__pycache__/diskusage.cpython-34.pyc b/v1/__pycache__/diskusage.cpython-34.pyc deleted file mode 100644 index 1507a630e073a70fd8eb580cbc1972d981659b7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 920 zcmYjPOK;Oa5T5ZPbsnV;P{jo}<={)Ls!~q~s?wH9r4dqEwT*-XoGY>crdU)bwSd$I((sRF31{4mt)MRUIV&*^CuMt zAI*|3qGB9tgL_vN=V)*T9@!f*eNFDR%UvwE7pz2f?ZN(sZJ1e50NeqS5bXd!9WfJS z?ku=Nh;7*D5~9UtGk{Mo;9N9$S+o|*{&L5F!DE9b2HzSyHTd4(fx#X(LF0aRT5oS} zZpCfg)>E(jFEV&ZC$Xcx_HAQl<PTh&#*LhZm_!&Df>VH4li4q`A&`-wh>?MTVe(U^w*dR}3p@Y- delta 49 zcmX@Zeu', methods=['GET']) -@auth.login_required -def get_singleDiskUsage(disk_name, other): - - if (diskUsage(disk_name)): - return jsonify({task_type: diskUsage(disk_name)}) - else: - abort(404) @app.route('/api/v1/uptimes', methods=['GET']) @auth.login_required def get_uptimes(): - up = uptime.uptime() - print(up) - return jsonify({'duration': up.duration, 'users': up.users, - 'load': up.load}) + try: + return jsonify({ 'uptime': timeSinceBoot() }) + except: + abort(404) + @app.route('/api/v1/uptimes/duration', methods=['GET']) @auth.login_required diff --git a/v1/uptime.py b/v1/uptime.py index e0a9591..4b6856c 100755 --- a/v1/uptime.py +++ b/v1/uptime.py @@ -3,7 +3,9 @@ # @Author: KevinMidboe # @Date: 2017-01-27 19:48:42 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-01-31 21:02:21 +# @Last Modified time: 2017-01-31 23:01:48 + +# TODO add better error handling to return statements from psutil import boot_time from time import time @@ -27,16 +29,14 @@ def timeSinceBoot(): # Return in day format if deltaSeconds >= 86400: - # TODO error handling return secToDay(deltaSeconds) # Return in hour format elif deltaSeconds < 86400 and deltaSeconds >= 0: - # TODO error handling return secToHour(deltaSeconds) else: - # Throw error - return 'Null' + # TODO Throw error + return None if __name__=="__main__": print(timeSinceBoot()) \ No newline at end of file