\u8bbe\u7f6e\u5b9a\u65f6\u6761\u76ee<\/strong><\/div>\n\u7528 Twisted \u5b9e\u73b0\u65f6\u95f4\u8ba1\u6570\u5668\u662f\u5229\u7528\u4e86 task.LoopingCall\u3002\u7136\u800c\uff0c\u7ed3\u675f\u5faa\u73af\u8c03\u7528\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u7528\u4e00\u4e2a\u5f02\u5e38\u3002\u5012\u8ba1\u65f6\u65f6\u949f\u603b\u4f1a\u505c\u6b62\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\u6765\u6307\u793a\u201c\u4e00\u5207\u6b63\u5e38\uff1b\u8ba1\u6570\u5668\u7ed3\u675f\u201d\uff1a<\/p>\n
class DoneError(Exception):\r\n pass\r\n<\/pre>\n\u73b0\u5728\u4f60\u5df2\u7ecf\u5199\u597d\u4e86\u5f02\u5e38\uff0c\u4f60\u53ef\u4ee5\u5199\u5b9a\u65f6\u5668\u4e86\u3002\u7b2c\u4e00\u6b65\u662f\u521b\u5efa\u4e00\u4e2a ipywidgets.Label \u7684\u6587\u672c\u6807\u7b7e\u7ec4\u4ef6\u3002\u5faa\u73af\u4f7f\u7528 divmod \u8ba1\u7b97\u51fa\u5206\u548c\u79d2\uff0c\u7136\u540e\u8bbe\u7f6e\u6807\u7b7e\u7684\u6587\u672c\u503c\uff1a<\/p>\n
def time_out_counter(reactor):\r\n label = ipywidgets.Label(\"Time left: 5:00\")\r\n current_seconds = datetime.timedelta(minutes=5).total_seconds()\r\n def decrement(count):\r\n nonlocal current_seconds\r\n current_seconds -= count\r\n time_left = datetime.timedelta(seconds=max(current_seconds, 0))\r\n minutes, left = divmod(time_left, minute)\r\n seconds = int(left.total_seconds())\r\n label.value = f\"Time left: {minutes}:{seconds:02}\"\r\n if current_seconds < 0:\r\n raise DoneError(\"finished\")\r\n minute = datetime.timedelta(minutes=1)\r\n call = task.LoopingCall.withCount(decrement)\r\n call.reactor = reactor\r\n d = call.start(1)\r\n d.addErrback(lambda f: f.trap(DoneError))\r\n return d, label\r\n<\/pre>\n\u4ece Jupyter \u7ec4\u4ef6\u4e2d\u4fdd\u5b58\u6587\u672c<\/strong><\/div>\n\u4e0b\u4e00\u6b65\u662f\u5199\u4e00\u4e9b\u4e1c\u897f\uff0c\u5c06\u4f60\u8f93\u5165\u7684\u6587\u5b57\u4fdd\u5b58\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5e76\u63d0\u4ea4\u5230 Git\u3002\u53e6\u5916\uff0c\u7531\u4e8e\u4f60\u8981\u5199 5 \u5206\u949f\u7684\u65e5\u8bb0\uff0c\u4f60\u9700\u8981\u4e00\u4e2a\u80fd\u7ed9\u4f60\u63d0\u4f9b\u5199\u5b57\u533a\u57df\u7684\u7ec4\u4ef6\uff08\u6eda\u52a8\u80af\u5b9a\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u4e00\u6b21\u80fd\u770b\u5230\u66f4\u591a\u7684\u6587\u5b57\u5c31\u66f4\u597d\u4e86\uff09\u3002<\/p>\n
\u8fd9\u5c31\u7528\u5230\u4e86\u7ec4\u4ef6 Textarea\uff0c\u8fd9\u662f\u4e00\u4e2a\u4f60\u53ef\u4ee5\u4e66\u5199\u7684\u6587\u672c\u5b57\u6bb5\uff0c\u800c Output \u5219\u662f\u7528\u6765\u7ed9\u51fa\u53cd\u9988\u7684\u3002\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a git push \u53ef\u80fd\u4f1a\u82b1\u70b9\u65f6\u95f4\u6216\u5931\u8d25\uff0c\u8fd9\u53d6\u51b3\u4e8e\u7f51\u7edc\u3002\u5982\u679c\u5907\u4efd\u5931\u8d25\uff0c\u7528\u53cd\u9988\u63d0\u9192\u7528\u6237\u5f88\u91cd\u8981\uff1a<\/p>\n
def editor(fname):\r\n textarea = ipywidgets.Textarea(continuous_update=False)\r\n textarea.rows = 20\r\n output = ipywidgets.Output()\r\n runner = functools.partial(subprocess.run, capture_output=True, text=True, check=True)\r\n def save(_ignored):\r\n with output:\r\n with open(fname, \"w\") as fpout:\r\n fpout.write(textarea.value)\r\n print(\"Sending...\", end='')\r\n try:\r\n runner([\"git\", \"add\", fname])\r\n runner([\"git\", \"commit\", \"-m\", f\"updated {fname}\"])\r\n runner([\"git\", \"push\"])\r\n except subprocess.CalledProcessError as exc:\r\n print(\"Could not send\")\r\n print(exc.stdout)\r\n print(exc.stderr)\r\n else:\r\n print(\"Done\")\r\n textarea.observe(save, names=\"value\")\r\n return textarea, output, save\r\n<\/pre>\ncontinuous_update=False \u662f\u4e3a\u4e86\u907f\u514d\u6bcf\u4e2a\u5b57\u7b26\u90fd\u4fdd\u5b58\u4e00\u904d\u5e76\u53d1\u9001\u81f3 Git\u3002\u76f8\u53cd\uff0c\u53ea\u8981\u8131\u79bb\u8f93\u5165\u7126\u70b9\uff0c\u5b83\u5c31\u4f1a\u4fdd\u5b58\u3002\u8fd9\u4e2a\u51fd\u6570\u4e5f\u8fd4\u56de save \u51fd\u6570\uff0c\u6240\u4ee5\u53ef\u4ee5\u660e\u786e\u5730\u8c03\u7528\u5b83\u3002<\/p>\n
\u521b\u5efa\u4e00\u4e2a\u5e03\u5c40<\/strong><\/div>\n\u6700\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 ipywidgets.VBox \u628a\u8fd9\u4e9b\u4e1c\u897f\u653e\u5728\u4e00\u8d77\u3002\u8fd9\u662f\u4e00\u4e2a\u5305\u542b\u4e00\u4e9b\u7ec4\u4ef6\u5e76\u5782\u76f4\u663e\u793a\u7684\u4e1c\u897f\u3002\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u65b9\u6cd5\u6765\u6392\u5217\u7ec4\u4ef6\uff0c\u4f46\u8fd9\u8db3\u591f\u7b80\u5355\uff1a<\/p>\n
def journal():\r\n date = str(datetime.date.today())\r\n title = f\"Log: Startdate {date}\"\r\n filename = os.path.join(f\"{date}.txt\")\r\n d, clock = time_out_counter(reactor)\r\n textarea, output, save = editor(filename)\r\n box = ipywidgets.VBox([\r\n ipywidgets.Label(title),\r\n textarea,\r\n clock,\r\n output\r\n ])\r\n d.addCallback(save)\r\n return box\r\n<\/pre>\nbiu\uff01\u4f60\u5df2\u7ecf\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5199\u65e5\u8bb0\u7684\u51fd\u6570\u4e86\uff0c\u6240\u4ee5\u662f\u65f6\u5019\u8bd5\u8bd5\u4e86\u3002<\/p>\n
journal()\r\n<\/pre>\n<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5bf9\u4e8e\u6211\u6700\u65b0\u7684\u4e3b\u9898\uff0c\u6211\u51b3\u5b9a\u8981\u6bcf\u5929\u5199\u4e00\u7bc7\u65e5\u8bb0\u3002\u6211\u559c\u6b22\u6709\u660e\u786e\u7684\u627f\u8bfa\uff0c\u6240\u4ee5\u6211\u627f\u8bfa\u6bcf\u5929\u5199 5 \u5206\u949f\u3002\u6211\u4e5f\u559c\u6b22\u6709\u53ef\u89c2\u5bdf\u7684\u627f […]<\/p>\n","protected":false},"author":1329,"featured_media":206641,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-206638","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/206638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=206638"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/206638\/revisions"}],"predecessor-version":[{"id":206643,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/206638\/revisions\/206643"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/206641"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=206638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=206638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=206638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}