Files
SMANAGE/backup/AKS/fors.py
T

67 lines
2.2 KiB
Python

import sys,os
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))#Re Dir
print(os.getcwd())
# 读/写/添
def openw(file, write, mode="1", encoding="UTF-8"):
if mode == "1" or mode == 1:
with open(file, "w", encoding=encoding) as f:
f.write(write)
elif mode == "2" or mode == 2:
with open(file, "wb") as f:
f.write(write)
def opena(file, write, mode="1", encoding="UTF-8"):
if mode == "1" or mode == 1:
with open(file, "a", encoding=encoding) as f:
f.write(write)
elif mode == "2" or mode == 2:
with open(file, "ab") as f:
f.write(write)
def openr(file, mode="1", encoding="UTF-8"):
if mode == "1" or mode == 1:
with open(file, "r", encoding=encoding) as f:
read = f.read()
elif mode == "2" or mode == 2:
with open(file, "rb") as f:
read = f.read()
return read
def replace_case(old, new, text):
index = text.lower().find(old.lower())
if index == -1:
return text
return replace_case(old, new, text[:index] + new + text[index + len(old):])
def replaces(dirs):
for i in os.listdir(dirs):
file:str=(dirs+"/"+i)
if os.path.isfile(file) and file.split(".")[-1].lower() == "html":
print(f"Now: {file}")
try:
read=openr(file)
read=read.replace("\"//","\"http://")
#read=read.replace("\"/","\"/AKS/")
#read=read.replace("'/","'/AKS/")
read=read.replace("\"/AKS/AKS/AKS/","\"/AKS/")
read=read.replace("'/AKS/AKS/AKS/","'/AKS/")
read=read.replace("2233.png","2233.jpg")
read=read.replace("'2233.jpg","2233.jpg")
read=read.replace('<script src="/AKS/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script>',"")
except:
print(f"Eow: {file}")
else:
openw(file,read)
if os.path.isdir(file):
replaces(file)
replaces("./")