i3: update jupyter-calculator script

This commit is contained in:
Julian Mutter 2022-10-27 20:05:48 +02:00
parent 3e9e99c24a
commit e1c834734d

View File

@ -41,7 +41,10 @@ def isNotebookRunning():
if __name__ == "__main__":
try:
if not isNotebookRunning():
subprocess.Popen(f"jupyter notebook --notebook-dir={NOTEBOOK_DIR} --port={PORT} --no-browser", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print("No notebook instance running. Starting it...")
subprocess.Popen(f"jupyter notebook --notebook-dir={NOTEBOOK_DIR} --port={PORT} --no-browser", shell=True)
else:
print("Notebook instance already running.")
max_wait_seconds = 3
delta_t_seconds = 0.1
@ -59,8 +62,12 @@ if __name__ == "__main__":
if current_wait_seconds >= max_wait_seconds:
raise Exception(f"Maximum wait time of {max_wait_seconds} exceeded!")
subprocess.call(f"cp {NOTEBOOK_DIR}calculator_template.ipynb {NOTEBOOK_DIR}calculator.ipynb", shell=True, stdout=None)
subprocess.call(f"electron 'http://localhost:{PORT}/notebooks/calculator.ipynb?token={token}'", shell=True, stdout=None)
subprocess.call(f"cp {NOTEBOOK_DIR}calculator_template.ipynb {NOTEBOOK_DIR}calculator.ipynb", shell=True)
# url = f"http://localhost:{PORT}/notebooks/calculator.ipynb?token={token}"
url = f"http://localhost:{PORT}/?token={token}"
subprocess.call(f"$BROWSER '{url}'", shell=True)
finally:
# TODO: not reliably working