Roll over API exceptions
This commit is contained in:
parent
d27bc0ab5b
commit
12d6c53985
2 changed files with 83 additions and 63 deletions
|
@ -5,5 +5,6 @@ zapp_binary(
|
||||||
deps = [
|
deps = [
|
||||||
py_requirement("colored"),
|
py_requirement("colored"),
|
||||||
py_requirement("octorest"),
|
py_requirement("octorest"),
|
||||||
|
py_requirement("pyyaml"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
import curses
|
import curses
|
||||||
|
from datetime import timedelta
|
||||||
|
from itertools import count
|
||||||
import os
|
import os
|
||||||
from time import sleep
|
|
||||||
import signal
|
import signal
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
from colored import fg, bg, attr
|
|
||||||
from octorest.client import OctoRest
|
from octorest.client import OctoRest
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def draw(screen, client):
|
def draw(screen, client):
|
||||||
|
@ -17,6 +19,8 @@ def draw(screen, client):
|
||||||
rows, cols = screen.getmaxyx()
|
rows, cols = screen.getmaxyx()
|
||||||
|
|
||||||
# Poll the API
|
# Poll the API
|
||||||
|
|
||||||
|
try:
|
||||||
job = client.job_info()
|
job = client.job_info()
|
||||||
# >>> client.job_info()
|
# >>> client.job_info()
|
||||||
# {'job': {'averagePrintTime': 7965.021392323004,
|
# {'job': {'averagePrintTime': 7965.021392323004,
|
||||||
|
@ -37,6 +41,7 @@ def draw(screen, client):
|
||||||
# 'printTimeLeft': 0,
|
# 'printTimeLeft': 0,
|
||||||
# 'printTimeLeftOrigin': None},
|
# 'printTimeLeftOrigin': None},
|
||||||
# 'state': 'Operational'}
|
# 'state': 'Operational'}
|
||||||
|
|
||||||
printer = client.printer()
|
printer = client.printer()
|
||||||
# >>> client.printer()
|
# >>> client.printer()
|
||||||
# {'sd': {'ready': False},
|
# {'sd': {'ready': False},
|
||||||
|
@ -65,7 +70,7 @@ def draw(screen, client):
|
||||||
file = job["job"]["file"]
|
file = job["job"]["file"]
|
||||||
progress = job["progress"]
|
progress = job["progress"]
|
||||||
completion = progress["completion"] / 100.0
|
completion = progress["completion"] / 100.0
|
||||||
time_remaining = progress["printTimeLeft"]
|
time_remaining = timedelta(seconds=progress["printTimeLeft"])
|
||||||
|
|
||||||
progress_cols = int(cols * completion)
|
progress_cols = int(cols * completion)
|
||||||
progress_line = ("#" * progress_cols) + ("-" * (cols - progress_cols))
|
progress_line = ("#" * progress_cols) + ("-" * (cols - progress_cols))
|
||||||
|
@ -77,6 +82,16 @@ def draw(screen, client):
|
||||||
|
|
||||||
screen.addstr(5, 0, progress_line)
|
screen.addstr(5, 0, progress_line)
|
||||||
|
|
||||||
|
for i, l in zip(count(7), yaml.dump({"job": job, "printer": printer}).splitlines()):
|
||||||
|
if i >= rows:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
screen.addstr(i, 0, l)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
screen.addstr(str(e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(os.path.expanduser("~/.config/octoprint-cli.ini"))
|
config.read(os.path.expanduser("~/.config/octoprint-cli.ini"))
|
||||||
|
@ -92,6 +107,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, kbdint)
|
signal.signal(signal.SIGTERM, kbdint)
|
||||||
|
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
@ -100,3 +116,6 @@ if __name__ == "__main__":
|
||||||
sleep(1)
|
sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
finally:
|
||||||
|
curses.endwin()
|
||||||
|
|
Loading…
Reference in a new issue