main_cli.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/python3
  2. import sys
  3. from netspeed import NetSpeed
  4. if len(sys.argv) < 2:
  5. print(
  6. """Usage:
  7. info -- show the information of your net speed
  8. up -- speed up
  9. down -- slow down""")
  10. else:
  11. my_netspeed = NetSpeed()
  12. if sys.argv[1] == "info":
  13. print("SpeedUp: %s\nNormal speed: %s %s\nSpeedup speed: %s Mbps\nLeft time: %sh"
  14. % (bool(my_netspeed.status), my_netspeed.old_speed, my_netspeed.old_speed_unit_name,
  15. my_netspeed.new_speed, my_netspeed.hours))
  16. elif sys.argv[1] == "up":
  17. if my_netspeed.hours == 0:
  18. print("Warning: Do not have any speedup time, speedup may failed!")
  19. status = my_netspeed.speed_up()
  20. if status:
  21. print("Speed up successfully.")
  22. else:
  23. print("Speed up failed!")
  24. sys.exit(1)
  25. elif sys.argv[1] == "down":
  26. status = my_netspeed.speed_down()
  27. if status:
  28. print("Slow down successfully.")
  29. else:
  30. print("Slow down failed!")
  31. sys.exit(1)