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

IndexError: list index out of range #3

Open
mehtaparitosh opened this issue May 25, 2021 · 1 comment
Open

IndexError: list index out of range #3

mehtaparitosh opened this issue May 25, 2021 · 1 comment

Comments

@mehtaparitosh
Copy link

$python3 bandwidth.py 500 MiB

Traceback (most recent call last):
File "bandwidth.py", line 57, in
main()
File "bandwidth.py", line 54, in main
monitor(limit, unit)
File "bandwidth.py", line 29, in monitor
if unit==l[5] and limit<l[4]:
IndexError: list index out of range

@mehtaparitosh
Copy link
Author

Altered it for python3

#!/usr/bin/env python

import os
import sys
import time
#import re
import threading
import subprocess
import tkinter
import tkinter.messagebox as tkMessageBox

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():
			tkMessageBox.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 callMonitor(limit, unit):
#	t=threading.Timer(4.0, monitor(limit, unit))
#	t.start()
#	monitor(limit, unit)

def main():
	if len(sys.argv) >3 or len(sys.argv)<3:
		print('command usage: python bandwidth.py <data usage in MiB or GiB>')
		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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant