techprotrade's picture
download
raw
751 Bytes
import re
from pathlib import Path
from base64 import b64decode
from hashlib import sha256
plist = [
Path(__file__).parent / "README.md",
Path(__file__).parent / "README_EN.md",
]
for p in plist:
imgdir = Path(__file__).parent / ".img"
if not imgdir.exists():
imgdir.mkdir()
d = p.read_text()
find = re.findall("(!\\[图片\\]\\(data:image/png;base64,.*?\\))", d, re.S)
for bimg in find:
bimgdata = bimg[len("![图片](data:image/png;base64,"): -1]
bimgpath = imgdir / f"{sha256(bimgdata.encode()).hexdigest()}.jpg"
print(bimgpath)
bimgpath.write_bytes(b64decode(bimgdata))
d = d.replace(bimg, f"![图片](.img/{bimgpath.name})\n")
p.write_text(d)

Xet Storage Details

Size:
751 Bytes
·
Xet hash:
bdf1b9afb68f3a4f41ec2cd7961e10451ba8a6626e026ce277a62925e86eee03

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.