@pandaoxi2022
2022-11-05T10:45:33.000000Z
字数 2952
阅读 319
帮助文档
开发者:大帅哥.
联系方式:电子邮箱.
你可以尝试运用不同的方法使用此程序。
更多使用方法,等待你去发现!
# Author:PanDaoxi
from tkinter.filedialog import askdirectory, askopenfilename
from sys import argv, exit, setrecursionlimit
from base64 import b64encode, b64decode
from os import remove, environ, mkdir
from pyautogui import screenshot
from os.path import exists
from easygui import msgbox
from time import strftime
from tkinter import Tk
window = Tk()
window.withdraw()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def makeXY():
a, b = width, height
x = gcd(a, b)
a /= x
b /= x
while a < 500 or b < 500:
a *= 2
b *= 2
return (a, b)
w, h = makeXY()
setrecursionlimit(114514)
vl = argv[1 : len(argv)]
title = "网课截图工具"
makeBase64 = lambda s : b64encode(s).decode()
filePath = "%s\\Desktop\\笔记拍照" % environ["UserProFile"]
if not exists(filePath):
mkdir(filePath)
def makeImage():
image = screenshot(region = (0, 0, width, height))
image.save("./temp.png")
with open("./temp.png", "rb") as f:
fileBase64 = makeBase64(f.read())
remove("./temp.png")
return fileBase64
def output(fileBase64):
altNumber = strftime("%Y%m%d")
today = "%s\\%s.html" % (filePath, altNumber)
if not exists(today):
with open(today, "w", encoding="utf-8") as f:
f.write("")
with open(today, "a", encoding="utf-8") as f:
f.write("<img alt=\"%s\" src=\"data:image/png;base64,%s\" width=\"%d\" height=\"%d\"/></br></br></br>\n" % (altNumber+strftime("%H%M%S"), fileBase64, w, h))
msgbox("保存成功!", title)
def getImage():
today = askopenfilename(title = title + ":读入笔记文件", initialdir = filePath, filetypes = (["已保存的笔记", "*.html",],))
while not exists(today):
today = askopenfilename(title = title + ":您使用了一个不合法的路径", initialdir = filePath, filetypes = (["*.html", "已保存的笔记"],))
with open(today, "r", encoding="utf-8") as f:
fr = f.read()
temp = fr.splitlines()
fd = {}
for i in temp:
alt = i[10 : 24]
fd[alt] = i.replace('<img alt="%s" src="data:image/png;base64,' % alt, "").replace("\" width=\"%d\" height=\"%d\"/></br></br></br>" % (1024, 576), "")
save = askdirectory(title = title + ":选择输出路径", initialdir = filePath)
while not exists(save):
save = askdirectory(title = title + ":您使用了一个不合法的路径", initialdir = filePath)
for i in fd:
t = "%s\\%s.png" % (save, i)
with open(t, "wb") as f:
f.write(b64decode(fd[i].encode()))
msgbox("输出完成!", title)
try:
if not len(vl):
msgbox("您没有添加任何参数。\n如果需要使用此程序,请添加参数以使用不同功能。\n\n如需帮助,请查看帮助文档:\nhttps://www.zybuluo.com/pandaoxi2022/note/2412946", title)
elif vl[0] == "export":
output(makeImage())
elif vl[0] == "import":
getImage()
else:
msgbox("没有相关的参数定义。\n请参阅帮助文档:\nhttps://www.zybuluo.com/pandaoxi2022/note/2412946", title)
except Exception as e:
msgbox("遇到bug啦!\n%s" % e, title)
exit()