This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/文本处理工具/剪贴板圆圈数字生成.ipynb

78 lines
2.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os,re\n",
"import win32clipboard as wc\n",
"import win32con\n",
"\n",
"# 获取剪切板内容\n",
"def getCopy():\n",
" wc.OpenClipboard()\n",
" t = wc.GetClipboardData(win32con.CF_UNICODETEXT)\n",
" wc.CloseClipboard()\n",
" return t\n",
"\n",
"# 写入剪切板内容\n",
"def setCopy(str):\n",
" wc.OpenClipboard()\n",
" wc.EmptyClipboard()\n",
" wc.SetClipboardData(win32con.CF_UNICODETEXT, str)\n",
" wc.CloseClipboard()\n",
"\n",
"\n",
"data = getCopy()\n",
"# print(modified_data)\n",
"modified_data = re.sub(r\"\\((\\d)\\)\",lambda x: \"\\\\textcircled{\"+x.group(1)+\"}\",data)\n",
"# print(modified_data)\n",
"modified_data = re.sub(r\"\\$\\\\textcircled\\{\\\\scriptsize\\{(\\d)\\}\\}\",lambda x: \"\\\\textcircled{\"+x.group(1)+\"}$\",modified_data)\n",
"modified_data = re.sub(r\"\\\\textcircled\\{\\\\scriptsize\\{(\\d)\\}\\}\",lambda x: \"\\\\textcircled{\"+x.group(1)+\"}\",modified_data)\n",
"\n",
"\n",
"setCopy(modified_data)\n",
"\n",
"with open(\"临时文件/outputfile.txt\",\"w\",encoding = \"utf8\") as f:\n",
" f.write(modified_data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "mathdept",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "ff3c292c316ba85de6f1ad75f19c731e79d694e741b6f515ec18f14996fe48dc"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}