From ef093aa867d4e87d7e4313f56ab30290b5372ba1 Mon Sep 17 00:00:00 2001 From: Adarsh Kushwah Date: Sat, 10 Oct 2020 04:09:41 +0530 Subject: [PATCH 1/3] add updated python3.x version --- bandwidth_py3.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 bandwidth_py3.py diff --git a/bandwidth_py3.py b/bandwidth_py3.py new file mode 100644 index 0000000..7f2a7e0 --- /dev/null +++ b/bandwidth_py3.py @@ -0,0 +1,54 @@ +import os +import sys +import time +import threading +import subprocess +import tkinter +import tkinter.messagebox + + +def monitor(limit, unit): + check = "vnstat" + #os.system(check) + proc = subprocess.Popen(check, shell=True, stdout=subprocess.PIPE) + output = proc.communicate() + output = str(output) + #print output + l = [] + for t in output.split(): + try: + if t == "MiB" or t == "GiB": + l.append(t) + else: + l.append(float(t)) + except ValueError: + pass + #print l + if unit == l[5] and limit < l[4]: + print("\nnetwork usage limit exceeded!\n") + top = tkinter.Tk() + + def hello(): + tkinter.messagebox.showinfo("Warning!", "Network usage limit exceeded!!!!") + B1 = tkinter.Button(top, text="Warning", command=hello) + B1.pack() + top.mainloop() + arg = [limit, unit] + threading.Timer(60.0, monitor, arg).start() + + +def main(): + if len(sys.argv) > 3 or len(sys.argv) < 3: + print('command usage: python bandwidth.py ') + print('example: python bandwidth.py 500 MiB') + print('or python bandwidth.py 2 GiB') + exit(1) + else: + limit = float(sys.argv[1]) + unit = str(sys.argv[2]) + #callMonitor(limit, unit) + monitor(limit, unit) + + +if __name__ == "__main__": + main() From 47348d7f7d2e740666adfed2a877b0eda9156c91 Mon Sep 17 00:00:00 2001 From: "Adarsh.S.Kushwah" <48567796+adarshkushwah@users.noreply.github.com> Date: Sat, 10 Oct 2020 14:14:04 +0530 Subject: [PATCH 2/3] Update bandwidth_py3.py --- bandwidth_py3.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bandwidth_py3.py b/bandwidth_py3.py index 7f2a7e0..9dca8f1 100644 --- a/bandwidth_py3.py +++ b/bandwidth_py3.py @@ -39,9 +39,9 @@ def hello(): def main(): if len(sys.argv) > 3 or len(sys.argv) < 3: - print('command usage: python bandwidth.py ') - print('example: python bandwidth.py 500 MiB') - print('or python bandwidth.py 2 GiB') + print('command usage: python3 bandwidth_py3.py ') + print('example: python3 bandwidth_py3.py 500 MiB') + print('or python3 bandwidth_py3.py 2 GiB') exit(1) else: limit = float(sys.argv[1]) From 9572893acc2e7f5ed63a6cf9969eb228927480db Mon Sep 17 00:00:00 2001 From: Adarsh Kushwah Date: Sat, 10 Oct 2020 14:16:57 +0530 Subject: [PATCH 3/3] update bandwidth_py3.py --- bandwidth_py3.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bandwidth_py3.py b/bandwidth_py3.py index 7f2a7e0..9dca8f1 100644 --- a/bandwidth_py3.py +++ b/bandwidth_py3.py @@ -39,9 +39,9 @@ def hello(): def main(): if len(sys.argv) > 3 or len(sys.argv) < 3: - print('command usage: python bandwidth.py ') - print('example: python bandwidth.py 500 MiB') - print('or python bandwidth.py 2 GiB') + print('command usage: python3 bandwidth_py3.py ') + print('example: python3 bandwidth_py3.py 500 MiB') + print('or python3 bandwidth_py3.py 2 GiB') exit(1) else: limit = float(sys.argv[1])