Introduction ✨
Contents
Introduction ✨#
Welcome to Programming Notebook, a notebook mainly about my scientific notes and gains in learning Programming and Geophysics, and I am very glad if it is helpful for your research.
Admonition
There is no guarantees of correctness, and if you spot an error or a doubtful statement, kindly let me know.
Enjoy ✨#
The main contents of the notebook are as follows:
About the Book ✨#
The notebook is powered by Jupyter Book, which uses MyST Markdown syntax.
All the source files are edited in VSCode, run_jb_build.py
is a Python script to build the HTML and fresh it in Chrome browser automatically.
run_jb_build.py
usesgit
to check whether any of the files have been changed. If something are changed, it will rebuild the notebook and refresh the HTML in Chrome browser.run_jb_build.py
usesgit
indev
branch, and after modifying all files, you need to switch tomain
branch, and push it to Github.put
run_jb_build.py
in the root directory of your notebook project, and run it before you edit anytime.
import os
import time
import subprocess
from selenium import webdriver
"""
Use jupyter-book to generate html automatically.
1. Download Chrome-driver Plug-in for selenium package from https://chromedriver.chromium.org/
2. Make sure the project have 'dev' branch
3. Run this script in the root directory of book-project
@Author: Fu Yin || Fri Jul 22 21:59:08 2022
"""
#%% Functions
def jb_build(driver,book):
print("Start:", time.ctime())
os.system(f"jb build {book}")
driver.refresh()
def git_status():
cmd_git = subprocess.Popen(['git status -s'], shell = True, \
stdin = subprocess.PIPE, stdout = subprocess.PIPE, cwd = "./")
cmd_out_raw = cmd_git.stdout.read()
cmd_git.wait()
cmd_git.stdout.close()
cmd_out = cmd_out_raw.decode()
out = cmd_out.split("\n")
return out
def git_commit():
os.system(""" git add . """)
os.system(""" git commit -m "auto" """)
def main():
driver= webdriver.Chrome()
driver.get(url)
os.system("git switch dev")
jb_build(driver, book)
while True:
time.sleep(sleep_time)
out = git_status()
if len(out) != 1:
print("Change number = ", len(out))
jb_build(driver, book)
git_commit()
else:
print("No change and continue...")
continue
#%% Main
url = "file:///path_to_your_notebook/book/_build/html/intro.html"
book= "./book" # jupyter-book build ./book
sleep_time = 0.1 # unit/s
if __name__ == '__main__':
main()
Acknowledgements ✨#
Many thanks to…
🍿 If you enjoy the blog, please consider sponsoring 🍿
⏬ For Chinese friends:
⏬ For Non-Chinese friends: