用户:
LWKevin0wvf小号查看:0 回复:0 评论:0 创建时间:2024-08-03T11:58:46
github仓库项目链接喵Qck320923/misc/project
GPL开源协议
项目:
一、EasyShutdown
(需要安装python编译环境,无需第三方库)
main.py
from configs import *
from tkinter import messagebox
import tkinter as tk
import json
#界面更新
def update_language():
root.title(LANGUAGES[current_language]["title"])
language.config(text = LANGUAGES[current_language]["buttons"]["language"])
style.config(text = LANGUAGES[current_language]["buttons"]["style"])
shutdown.config(text = LANGUAGES[current_language]["buttons"]["shutdown"])
sleep.config(text = LANGUAGES[current_language]["buttons"]["sleep"])
reboot.config(text = LANGUAGES[current_language]["buttons"]["reboot"])
def update_style():
root.config(bg=STYLES[current_style]["bg"])
language.config(bg=STYLES[current_style]["bg"], fg=STYLES[current_style]["fg"])
style.config(bg=STYLES[current_style]["bg"], fg=STYLES[current_style]["fg"])
shutdown.config(bg=STYLES[current_style]["bg"], fg=STYLES[current_style]["fg"])
sleep.config(bg=STYLES[current_style]["bg"], fg=STYLES[current_style]["fg"])
reboot.config(bg=STYLES[current_style]["bg"], fg=STYLES[current_style]["fg"])
#更改设置
def change_language(new_lang):#切换语言
global current_language
current_language = new_lang
update_language()
with open("config.json", "w", encoding="utf-8") as f:
json.dump({"language": new_lang,"style": current_style}, f, ensure_ascii=False, indent=4)
def change_style(new_style):#切换UI风格样式
global current_style
current_style = new_style
update_style()
with open("config.json", "w", encoding="utf-8") as f:
json.dump({"language": current_language,"style": new_style}, f, ensure_ascii=False, indent=4)
#事件
def on_select(choice):#作出选择后将选项写入choice.txt临时文件传递给bat文件
with open("choice.txt", "w") as f:
f.write(choice)
root.destroy()
def on_closing():
if messagebox.askokcancel(LANGUAGES[current_language]["events"]["on_closing"]["title"], LANGUAGES[current_language]["events"]["on_closing"]["content"]):
with open("choice.txt", "w") as f:
f.write("close")
root.destroy() # 如果用户点击确定,则销毁窗口
#界面显示
def create_choice_window():#创建选择窗口
global root
root = tk.Tk()
root.title(LANGUAGES[current_language]["title"])
root.geometry("480x360")
root.protocol("WM_DELETE_WINDOW", on_closing)
global language, style, shutdown, sleep, reboot
language = tk.Button(root, command=lambda: change_language("en" if current_language == "zh" else "zh"))
language.pack(pady=10)
style = tk.Button(root, command=lambda: change_style("dark" if current_style == "default" else "default"))
style.pack(pady=10)
shutdown = tk.Button(root, width=30, command=lambda: on_select("shutdown"))
shutdown.pack(pady=10)
sleep = tk.Button(root, width=30, command=lambda: on_select("sleep"))
sleep.pack(pady=10)
reboot = tk.Button(root, width=30, command=lambda: on_select("reboot"))
reboot.pack(pady=10)
update_language()
update_style()
root.mainloop()
if __name__ == "__main__":
create_choice_window()
configs.py
import json
# 语言字典
LANGUAGES = {
"zh": {
"title": "简易关机 v0.0.1 - 作者:L.W.Kevin0wvf",
"buttons": {
"language": "切换语言(zh/en)",
"style": "切换UI风格样式",
"shutdown": "关机",
"sleep": "睡眠",
"reboot": "重启"
},
"events": {
"on_closing": {
"title": "退出",
"content": "您想要退出吗?"
}
}
},
"en": {
"title": "Easy Shutdown v0.0.1 - Author:L.W.Kevin0wvf",
"buttons": {
"language": "Toggle the language(zh/en)",
"style": "Toggle the UI style",
"shutdown": "Shutdown",
"sleep": "Sleep",
"reboot": "Reboot"
},
"events": {
"on_closing": {
"title": "Quit",
"content": "Do you want to quit?"
}
}
}
}
# UI风格样式
STYLES = {
"default": {
"fg": "#000000",
"bg": "#f0f0f0"
},
"dark": {
"fg": "#ffffff",
"bg": "#202020"
}
}
try:
with open("config.json", "r", encoding="utf-8") as f:
config = json.load(f)
# 当前语言
current_language = config["language"]
# 当前UI风格样式
current_style = config["style"]
except FileNotFoundError:
config = {"language": "zh", "style": "default"}
# 添加config配置文件
with open("config.json", "w", encoding="utf-8") as f:
json.dump(config, f, ensure_ascii=False, indent=4)
# 当前语言
current_language = config["language"]
# 当前UI风格样式
current_style = config["style"]
easy_shutdown.bat
@echo off
title EasyShutdown v0.0.1
echo EasyShutdown v0.0.1 is running!
echo Waiting for the operation...
python main.py
:wait_for_file
if not exist choice.txt (
timeout /t 1 >nul
goto wait_for_file
)
echo Get a response.
set /p CHOICE=<choice.txt
set time=5
if "%CHOICE%"=="shutdown" (
shutdown /s /t %time%
) else if "%CHOICE%"=="sleep" (
rundll32.exe user32.dll LockWorkStation
) else if "%CHOICE%"=="reboot" (
shutdown /r /t %time%
) else if "%CHOICE%"=="close" (
echo There is no operation, and the program has ended.
) else (
echo Error: Invalid selection or file is corrupted.
)
del choice.txt
rd /s /q __pycache__
config.json是存储配置的文件,如果没有会自动创建,这里省略config.json文件。
二、RMBSend
(需要安装python编译环境,需要喵auto第三方库(程序使用喵auto3.9.11.17.4版本),需要用到图片,需要运行前登录客户端微信)(github仓库中含有打包后的exe文件压缩后分卷后的2个7z文件(受github文件最大25mb限制),未加密,需要合并解压)(开源后有一次细节的更新(当通讯录列表(GetAllFriends)(不包括群聊)中找不到好友/群聊后,直接试图ChatWith),但是没有重新打包开源)
main.py
from configs import *
from algorithm import *
from tkinter import messagebox
import tkinter as tk
import json
import 喵auto
import copy
喵 = 喵auto.WeChat()
friends = 喵.GetAllFriends()
#界面更新
def update_language():
root.title(LANGUAGES[current_language]["title"])
language.config(text = LANGUAGES[current_language]["buttons"]["language"])
style.config(text = LANGUAGES[current_language]["buttons"]["style"])
send.config(text = LANGUAGES[current_language]["buttons"]["send"])
if inputing:
window.title(LANGUAGES[current_language]["events"]["on_send"]["title"])
search_tips.config(text = LANGUAGES[current_language]["events"]["on_send"]["search_tips"])
money_tips.config(text = LANGUAGES[current_language]["events"]["on_send"]["money_tips"])
sendConfirm.config(text = LANGUAGES[current_language]["events"]["on_send"]["send"])
confirm.config(text = LANGUAGES[current_language]["events"]["on_send"]["confirm"])
refresh.config(text = LANGUAGES[current_language]["events"]["on_send"]["refresh"])
def update_style():
root.config(bg = STYLES[current_style]["bg"])
language.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
style.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
send.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
if inputing:
window.config(bg = STYLES[current_style]["bg"])
search_tips.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
search.config(insertbackground = STYLES[current_style]["ibg"], bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
select_box.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
money_tips.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
money.config(insertbackground = STYLES[current_style]["ibg"], bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
sendConfirm.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
confirm.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
refresh.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
#更改设置
def change_language(new_lang):#切换语言
global current_language
current_language = new_lang
update_language()
with open("config.json", "w", encoding="utf-8") as f:
json.dump({"language": new_lang,"style": current_style}, f, ensure_ascii = False, indent = 4)
def change_style(new_style):#切换UI风格样式
global current_style
current_style = new_style
update_style()
with open("config.json", "w", encoding="utf-8") as f:
json.dump({"language": current_language,"style": new_style}, f, ensure_ascii = False, indent = 4)
#刷新会话列表options
def refreshSessionList(refresh = False):
global search, options, friends
if refresh:
friends = 喵.GetAllFriends()
options = friends.copy()
i = 0
while i < len(options):
options[i] = options[i]["nickname"]
if search.get() and not search.get() in options[i]:
options.pop(i)
else:
i += 1
#money输入检验
def validate_input(new_value):
if new_value == "":
return True
elif "." in new_value:
return False
try:
if float(new_value) > 0 and int(float(new_value)) == float(new_value):
return True
return False
except ValueError:
return False
#事件
def on_closing():
if messagebox.askokcancel(LANGUAGES[current_language]["events"]["on_closing"]["title"], LANGUAGES[current_language]["events"]["on_closing"]["content"]):
root.destroy()
def on_refresh(refresh = False):
global options, select_box, selected_option
refreshSessionList(refresh)
menu = select_box["menu"]
menu.delete(0, tk.END)#删除所有选项
#为Menu添加新的选项
for option in options:
menu.add_command(label = option, command = lambda v = option: selected_option.set(v))
#刷新默认选项
if len(options):
selected_option.set(options[0])
else:
selected_option.set("")
def on_select_change():
print(selected_option.get())
def on_send_closing():
global inputing, window
inputing = False
window.destroy()
def on_sendConfirm():
if money.get() == "":
return
else:
money_amount = int(float(money.get()))
喵.ChatWith(selected_option.get())
nums = calculate(money_amount)
for i in range(len(nums)):#遍历nums
for _ in range(nums[i]):
喵.SendFiles(f"RMB{par[i]}.png")
global inputing
inputing = False
def on_send():
global inputing
if inputing:
messagebox.askokcancel(LANGUAGES[current_language]["events"]["on_send"]["repeat"]["title"], LANGUAGES[current_language]["events"]["on_send"]["repeat"]["content"])
return
inputing = True
global root, window, search_tips, search, confirm, refresh, select_box, money_tips, money, sendConfirm
window = tk.Toplevel(root)
window.title(LANGUAGES[current_language]["events"]["on_send"]["title"])
window.geometry("360x270")
window.protocol("WM_DELETE_WINDOW", on_send_closing)
search_tips = tk.Label(window, text = LANGUAGES[current_language]["events"]["on_send"]["search_tips"])
search_tips.pack()
search = tk.Entry(window)
search.pack()
confirm = tk.Button(window, text = LANGUAGES[current_language]["events"]["on_send"]["confirm"], command = lambda: on_refresh())
confirm.pack()
refresh = tk.Button(window, text = LANGUAGES[current_language]["events"]["on_send"]["refresh"], command = lambda: on_refresh(True))
refresh.pack()
global options, selected_option
refreshSessionList()
selected_option = tk.StringVar(window)
selected_option.set(options[0])#默认选项
select_box = tk.OptionMenu(window, selected_option, *options)
select_box.pack()
money_tips = tk.Label(window, text = LANGUAGES[current_language]["events"]["on_send"]["money_tips"])
money_tips.pack()
validation = window.register(validate_input)#注册检验函数
money = tk.Entry(window, validate = "key", validatecommand = (validation, "%P"))#应用检验函数
money.pack()
sendConfirm = tk.Button(window, text = LANGUAGES[current_language]["events"]["on_send"]["send"], command = lambda: on_sendConfirm())
sendConfirm.pack()
update_style()
#界面显示
def create_root_window():#创建主窗口
global root
root = tk.Tk()
root.title(LANGUAGES[current_language]["title"])
root.geometry("480x270")
root.protocol("WM_DELETE_WINDOW", on_closing)
global language, style, send
language = tk.Button(root, command = lambda: change_language("en" if current_language == "zh" else "zh"))
language.pack(pady = 10)
style = tk.Button(root, command = lambda: change_style("dark" if current_style == "default" else "default"))
style.pack(pady = 10)
send = tk.Button(root, width = 30, command = lambda: on_send())
send.pack(pady = 10)
update_language()
update_style()
root.mainloop()
if __name__ == "__main__":
create_root_window()
configs.py
import json
# 语言字典
LANGUAGES = {
"zh": {
"title": "人民币发送 v0.0.1 - 作者:L.W.Kevin0wvf",
"buttons": {
"language": "切换语言(zh/en)",
"style": "切换UI风格样式",
"send": "发送"
},
"events": {
"on_closing": {
"title": "退出",
"content": "您想要退出吗?"
},
"on_send": {
"title": "发送人民币配置",
"search_tips": "🔍搜索:",
"confirm": "搜索",
"refresh": "刷新",
"money_tips": "💴钱数:",
"send": "发送",
"repeat": {
"title": "发送",
"content": "请勿打开多个发送配置窗口"
}
}
}
},
"en": {
"title": "RMB Send v0.0.1 - Author:L.W.Kevin0wvf",
"buttons": {
"language": "Toggle the language(zh/en)",
"style": "Toggle the UI style",
"send": "Send"
},
"events": {
"on_closing": {
"title": "Quit",
"content": "Do you want to quit?"
},
"on_send": {
"title": "Send RMB configs",
"search_tips": "🔍Search:",
"confirm": "Search",
"refresh": "Refresh",
"money_tips": "💴Amount of money:",
"send": "Send",
"repeat": {
"title": "Send",
"content": "Do not open more than one send configuration window"
}
}
}
}
}
# UI风格样式
STYLES = {
"default": {
"fg": "#000000",
"bg": "#f0f0f0",
"ibg": "#000000"
},
"dark": {
"fg": "#ffffff",
"bg": "#202020",
"ibg": "#ffffff"
}
}
try:
with open("config.json", "r", encoding="utf-8") as f:
config = json.load(f)
# 当前语言
current_language = config["language"]
# 当前UI风格样式
current_style = config["style"]
except FileNotFoundError:
config = {"language": "zh", "style": "default"}
# 添加config配置文件
with open("config.json", "w", encoding="utf-8") as f:
json.dump(config, f, ensure_ascii=False, indent=4)
# 当前语言
current_language = config["language"]
# 当前UI风格样式
current_style = config["style"]
inputing = False
par = [喵]
algorithm.py
from configs import par
def calculate(m):#计算最少数量纸币的组合方法(贪心算法)
res = []
for p in par:
if m >= p:
res.append(m // p)
m %= p
else:
res.append(0)
return res
更新后的main.py
from configs import *
from algorithm import *
from tkinter import messagebox
import tkinter as tk
import json
import 喵auto
import copy
喵 = 喵auto.WeChat()
friends = 喵.GetAllFriends()#获取所有微信好友(不包括群聊、自己、公众号、喵、文件传输助手、微信运动等)
#界面更新
def update_language():
root.title(LANGUAGES[current_language]["title"])
language.config(text = LANGUAGES[current_language]["buttons"]["language"])
style.config(text = LANGUAGES[current_language]["buttons"]["style"])
send.config(text = LANGUAGES[current_language]["buttons"]["send"])
if inputing:
window.title(LANGUAGES[current_language]["events"]["on_send"]["title"])
search_tips.config(text = LANGUAGES[current_language]["events"]["on_send"]["search_tips"])
money_tips.config(text = LANGUAGES[current_language]["events"]["on_send"]["money_tips"])
sendConfirm.config(text = LANGUAGES[current_language]["events"]["on_send"]["send"])
confirm.config(text = LANGUAGES[current_language]["events"]["on_send"]["confirm"])
refresh.config(text = LANGUAGES[current_language]["events"]["on_send"]["refresh"])
def update_style():
root.config(bg = STYLES[current_style]["bg"])
language.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
style.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
send.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
if inputing:
window.config(bg = STYLES[current_style]["bg"])
search_tips.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
search.config(insertbackground = STYLES[current_style]["ibg"], bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
select_box.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
money_tips.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
money.config(insertbackground = STYLES[current_style]["ibg"], bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
sendConfirm.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
confirm.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
refresh.config(bg = STYLES[current_style]["bg"], fg = STYLES[current_style]["fg"])
#更改设置
def change_language(new_lang):#切换语言
global current_language
current_language = new_lang
update_language()
with open("config.json", "w", encoding="utf-8") as f:
json.dump({"language": new_lang,"style": current_style}, f, ensure_ascii = False, indent = 4)
def change_style(new_style):#切换UI风格样式
global current_style
current_style = new_style
update_style()
with open("config.json", "w", encoding="utf-8") as f:
json.dump({"language": current_language,"style": new_style}, f, ensure_ascii = False, indent = 4)
#刷新会话列表options
def refreshSessionList(refresh = False):
global search, options, friends
if refresh:
friends = 喵.GetAllFriends()
options = friends.copy()
i = 0
while i < len(options):
options[i] = options[i]["nickname"]
if search.get() and not search.get() in options[i]:
options.pop(i)
else:
i += 1
#money输入检验
def validate_input(new_value):
if new_value == "":
return True
elif "." in new_value:
return False
try:
if float(new_value) > 0 and int(float(new_value)) == float(new_value):
return True
return False
except ValueError:
return False
#事件
def on_closing():
if messagebox.askokcancel(LANGUAGES[current_language]["events"]["on_closing"]["title"], LANGUAGES[current_language]["events"]["on_closing"]["content"]):
root.destroy()
def on_refresh(refresh = False):
global options, select_box, selected_option
refreshSessionList(refresh)
menu = select_box["menu"]
menu.delete(0, tk.END)#删除所有选项
#为Menu添加新的选项
for option in options:
menu.add_command(label = option, command = lambda v = option: selected_option.set(v))
#刷新默认选项
if len(options):
selected_option.set(options[0])
else:
selected_option.set("")
def on_select_change():
print(selected_option.get())
def on_send_closing():
global inputing, window
inputing = False
window.destroy()
def on_sendConfirm():
if money.get() == "":
return
else:
money_amount = int(float(money.get()))
if selected_option.get() == "":
if search.get() == "":
return
else:
喵.ChatWith(search.get())
else:
喵.ChatWith(selected_option.get())
nums = calculate(money_amount)
for i in range(len(nums)):#遍历nums
for _ in range(nums[i]):
喵.SendFiles(f"RMB{par[i]}.png")
global inputing
inputing = False
def on_send():
global inputing
if inputing:
messagebox.askokcancel(LANGUAGES[current_language]["events"]["on_send"]["repeat"]["title"], LANGUAGES[current_language]["events"]["on_send"]["repeat"]["content"])
return
inputing = True
global root, window, search_tips, search, confirm, refresh, select_box, money_tips, money, sendConfirm
window = tk.Toplevel(root)
window.title(LANGUAGES[current_language]["events"]["on_send"]["title"])
window.geometry("360x270")
window.protocol("WM_DELETE_WINDOW", on_send_closing)
search_tips = tk.Label(window, text = LANGUAGES[current_language]["events"]["on_send"]["search_tips"])
search_tips.pack()
search = tk.Entry(window)
search.pack()
confirm = tk.Button(window, text = LANGUAGES[current_language]["events"]["on_send"]["confirm"], command = lambda: on_refresh())
confirm.pack()
refresh = tk.Button(window, text = LANGUAGES[current_language]["events"]["on_send"]["refresh"], command = lambda: on_refresh(True))
refresh.pack()
global options, selected_option
refreshSessionList()
selected_option = tk.StringVar(window)
selected_option.set(options[0])#默认选项
select_box = tk.OptionMenu(window, selected_option, *options)
select_box.pack()
money_tips = tk.Label(window, text = LANGUAGES[current_language]["events"]["on_send"]["money_tips"])
money_tips.pack()
validation = window.register(validate_input)#注册检验函数
money = tk.Entry(window, validate = "key", validatecommand = (validation, "%P"))#应用检验函数
money.pack()
sendConfirm = tk.Button(window, text = LANGUAGES[current_language]["events"]["on_send"]["send"], command = lambda: on_sendConfirm())
sendConfirm.pack()
update_style()
#界面显示
def create_root_window():#创建主窗口
global root
root = tk.Tk()
root.title(LANGUAGES[current_language]["title"])
root.geometry("480x270")
root.protocol("WM_DELETE_WINDOW", on_closing)
global language, style, send
language = tk.Button(root, command = lambda: change_language("en" if current_language == "zh" else "zh"))
language.pack(pady = 10)
style = tk.Button(root, command = lambda: change_style("dark" if current_style == "default" else "default"))
style.pack(pady = 10)
send = tk.Button(root, width = 30, command = lambda: on_send())
send.pack(pady = 10)
update_language()
update_style()
root.mainloop()
if __name__ == "__main__":
create_root_window()
RMB_send.bat(只是提供更便捷的运行方式(双击bat),打包的exe文件中不包括也不需要RMB_send.bat文件)
@echo off
title RMBSend v0.0.1
echo RMBSend v0.0.1 is running!
python main.py
:wait_for_file
rd /s /q __pycache__
图片在github仓库中
config.json是存储配置的文件,如果没有会自动创建,这里再次省略config.json文件。