Tools / ImgManage.py
dong625's picture
Upload 14 files
12e1035 verified
raw
history blame contribute delete
No virus
9.61 kB
import os
import shutil
import time
import argparse
import requests
def get_daily_sentence(types=['a']):
params = {
'c': types
}
response = requests.get("https://v1.hitokoto.cn/", params=params)
if response.status_code == 200:
data = response.json()
return "\033[36m\033[4m" + data["hitokoto"] + "\033[0m"
else:
return " \033[36m\033[4m静待花开会有时,守得云开见月明\033[0m"
def ClearLike():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo/Like"
if os.path.exists(path):
shutil.rmtree(path)
print(f"{path} 已删除")
else:
print(f"{path} 不存在")
def PackLike():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo/Like"
zip_path = "/mnt/workspace/Like.zip"
if os.path.exists(path):
if os.path.exists(zip_path):
os.system(f"7z a {zip_path} {path} -y")
print("检测到旧的Like包存在,已经覆盖,已保存在根目录")
else:
os.system(f"7z a {zip_path} {path}")
print("打包完成,已保存在根目录,文件名为Like.zip")
else:
print(f"{path} 文件夹不存在")
def ClearUpscale():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo/Upscale"
if os.path.exists(path):
shutil.rmtree(path)
print(f"{path} 已删除")
else:
print(f"{path} 不存在")
def PackUpscale():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo/Upscale"
zip_path = "/mnt/workspace/Upscale.zip"
if os.path.exists(path):
if os.path.exists(zip_path):
os.system(f"7z a {zip_path} {path} -y")
print("检测到旧的Upscale包存在,已经覆盖,已保存在根目录")
else:
os.system(f"7z a {zip_path} {path}")
print("打包完成,已保存在根目录,文件名为Upscale.zip")
else:
print(f"{path} 文件夹不存在")
def ClearAll():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l'])
print(daily_sentence)
path = "/mnt/workspace/Photo/"
if os.path.exists(path):
for item in os.listdir(path):
item_path = os.path.join(path, item)
if os.path.isdir(item_path):
shutil.rmtree(item_path)
print(f"{path} 已清空")
else:
print(f"{path} 文件夹不存在")
def PackAll():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo"
zip_path = "/mnt/workspace/Photo.zip"
if os.path.exists(path):
if os.path.exists(zip_path):
os.system(f"7z a {zip_path} {path} -y")
print("检测到旧的Photo包存在,已经覆盖,已保存在根目录")
else:
os.system(f"7z a {zip_path} {path}")
print("打包完成,已保存在根目录,文件名为Photo.zip")
else:
print(f"{path} 文件夹不存在")
def ClearLikeUpscale():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo/Like_Upscale"
if os.path.exists(path):
shutil.rmtree(path)
print(f"{path} 已删除")
else:
print(f"{path} 不存在")
def PackLikeUpscale():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = "/mnt/workspace/Photo/Like_Upscale"
zip_path = "/mnt/workspace/Like_Upscale.zip"
if os.path.exists(path):
if os.path.exists(zip_path):
os.system(f"7z a {zip_path} {path} -y")
print("检测到旧的Like_Upscale包存在,已经覆盖,已保存在根目录")
else:
os.system(f"7z a {zip_path} {path}")
print("打包完成,已保存在根目录,文件名为Like_Upscale.zip")
else:
print(f"{path} 文件夹不存在\n")
print("请在SD界面-后期处理-批量处理文件夹中设置\n")
print("输入目录")
print("/mnt/workspace/Photo/Like\n")
print("输出目录")
print("/mnt/workspace/Photo/Like_Upscale\n")
def Cleartodaytxt2img():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
current_time = time.localtime()
formatted_time = time.strftime("%Y-%m-%d", current_time)
todaypath = f"/mnt/workspace/Photo/txt2img/{formatted_time}"
if os.path.exists(todaypath):
shutil.rmtree(todaypath)
print(f"{todaypath} 已删除")
else:
print(f"{todaypath} 不存在")
def Packtodaytxt2img():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
current_time = time.localtime()
formatted_time = time.strftime("%Y-%m-%d", current_time)
todaypath = f"/mnt/workspace/Photo/txt2img/{formatted_time}"
zip_path = f"/mnt/workspace/【文生图】{formatted_time}.zip"
if os.path.exists(todaypath):
if os.path.exists(zip_path):
os.system(f"7z a {zip_path} {todaypath} -y")
print(f"检测到旧的【文生图】{formatted_time}包存在,已经覆盖,已保存在根目录")
else:
os.system(f"7z a {zip_path} {todaypath}")
print(f"打包完成,已保存在根目录,文件名为【文生图】{formatted_time}.zip")
else:
print(f"{todaypath} 文件夹不存在")
def cleartodayimg2img():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
current_time = time.localtime()
formatted_time = time.strftime("%Y-%m-%d", current_time)
todaypath = f"/mnt/workspace/Photo/txt2img/{formatted_time}"
if os.path.exists(todaypath):
shutil.rmtree(todaypath)
print(f"{todaypath} 已删除")
else:
print(f"{todaypath} 不存在")
def Packtodayimg2img():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
current_time = time.localtime()
formatted_time = time.strftime("%Y-%m-%d", current_time)
todaypath = f"/mnt/workspace/Photo/img2img/{formatted_time}"
zip_path = f"/mnt/workspace/【图生图】{formatted_time}.zip"
if os.path.exists(todaypath):
if os.path.exists(zip_path):
os.system(f"7z a {zip_path} {todaypath} -y")
print(f"检测到旧的【图生图】{formatted_time}包存在,已经覆盖,已保存在根目录")
else:
os.system(f"7z a {zip_path} {todaypath}")
print(f"打包完成,已保存在根目录,文件名为【图生图】{formatted_time}.zip")
else:
print(f"{todaypath} 文件夹不存在")
def Clearoriginalimg2img():
daily_sentence = get_daily_sentence(['a','b','c','d','e','f','g','h','j','k','l',])
print(daily_sentence)
path = f"/mnt/workspace/Photo/img2img/original"
if os.path.exists(path):
shutil.rmtree(path)
print(f"{path} 已删除")
else:
print(f"{path} 不存在")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument("-ClearLike", action="store_true", help="Clear Like folder")
parser.add_argument("-PackLike", action="store_true", help="Pack Like folder")
parser.add_argument("-ClearUpscale", action="store_true", help="Clear Upscale folder")
parser.add_argument("-PackUpscale", action="store_true", help="Pack Upscale folder")
parser.add_argument("-ClearAll", action="store_true", help="Clear All folder")
parser.add_argument("-PackAll", action="store_true", help="Pack All folder")
parser.add_argument("-ClearLikeUpscale", action="store_true", help="Clear Like_Upscale folder")
parser.add_argument("-PackLikeUpscale", action="store_true", help="Pack Like_Upscale folder")
parser.add_argument("-Cleartodaytxt2img", action="store_true", help="Clear todaytxt2img folder")
parser.add_argument("-Packtodaytxt2img", action="store_true", help="Pack todaytxt2img folder")
parser.add_argument("-Packtodayimg2img", action="store_true", help="Pack todayimg2img folder")
parser.add_argument("-Cleartodayimg2img", action="store_true", help="Clear todayimg2img folder")
parser.add_argument("-Clearoriginalimg2img", action="store_true", help="Pack Clearoriginalimg2img folder")
args = parser.parse_args()
if args.ClearLike:
ClearLike()
elif args.PackLike:
PackLike()
elif args.ClearUpscale:
ClearUpscale()
elif args.PackUpscale:
PackUpscale()
elif args.ClearAll:
ClearAll()
elif args.PackAll:
PackAll()
elif args.ClearLikeUpscale:
ClearLikeUpscale()
elif args.PackLikeUpscale:
PackLikeUpscale()
elif args.Cleartodaytxt2img:
Cleartodaytxt2img()
elif args.Packtodaytxt2img:
Packtodaytxt2img()
elif args.Packtodayimg2img:
Packtodayimg2img()
elif args.Cleartodayimg2img:
Cleartodayimg2img()
elif args.Clearoriginalimg2img:
Clearoriginalimg2img()