Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add python3.x version #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions bandwidth_py3.py
Original file line number Diff line number Diff line change
@@ -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: python3 bandwidth_py3.py <data usage in MiB or GiB>')
print('example: python3 bandwidth_py3.py 500 MiB')
print('or python3 bandwidth_py3.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()