都是一些电脑里翻出来的很久以前的幼稚小玩意,没想好要不要删干净,干脆存起来留档,感觉以后可能有点用吧
CDK 自动存txt工具
实时监控: 脚本运行后会一直盯着你的系统剪贴板(即你执行“复制”操作的内容)。
特定匹配: 它利用正则表达式 ^[A-Za-z0-9]{12}$ 来筛选内容。只有当你复制的内容正好是 12 位且只包含数字或字母时,它才会触发动作。这通常是很多游戏或平台的兑换码格式。
自动存储: 一旦捕获到符合条件的字符串,它会立刻将其写入一个以当前时间命名的文本文件中(例如 output_20260107xxxx.txt)。
防止重复: 脚本在运行期间会记录已经保存过的码。如果你不小心重复复制了同一个码,它会提示“重复”并跳过,不会在文件里记录两次。
窗口置顶与调整: 脚本启动时,会自动把当前的命令行窗口(CMD)调整为 600x600 的大小,并尝试将其置顶显示。
后台运行: 监听过程是在一个独立的线程中进行的,这意味着它在后台静默工作,不会阻塞程序运行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import os import pyperclip import win32gui import win32con import re import threading from datetime import datetime
def save_exchange_code_to_file(exchange_code, output_file): with threading.Lock(): with open(output_file, 'a') as file: file.write(exchange_code + '\n')
def is_exchange_code(text): pattern = r'^[A-Za-z0-9]{12}$' return re.match(pattern, text.strip()) is not None
def set_window_size(hwnd, width, height): win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, width, height, win32con.SWP_SHOWWINDOW)
def clipboard_listener(): processed_codes = set() while True: try: current_clipboard = pyperclip.waitForNewPaste()
if is_exchange_code(current_clipboard): exchange_code = current_clipboard.strip() if exchange_code not in processed_codes: print("捕获到兑换码:", exchange_code) save_exchange_code_to_file(exchange_code, output_file) processed_codes.add(exchange_code) else: print("重复的兑换码,已经处理过:", exchange_code) except Exception as e: print("剪贴板监听发生异常:", str(e))
def print_author_info(): author_info = """ 作者:lrwy """ print(author_info)
if __name__ == "__main__": print_author_info()
script_dir = os.path.dirname(os.path.realpath(__file__)) now = datetime.now().strftime("%Y%m%d%H%M%S") output_file = os.path.join(script_dir, f'output_{now}.txt')
print("正在监听剪贴板,请复制兑换码...")
cmd_window = win32gui.GetForegroundWindow() set_window_size(cmd_window, 600, 600)
clipboard_thread = threading.Thread(target=clipboard_listener, daemon=True) clipboard_thread.start()
clipboard_thread.join()
|
兑换码复制
和上面的脚本相反,是输出用的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import os import json import pyperclip import win32gui import win32con
def read_file_lines(file_path): with open(file_path, 'r', encoding='utf-8') as file: lines = file.readlines() return lines
def is_containing_chinese_or_empty(text): return any('\u4e00' <= char <= '\u9fff' for char in text) or not text.strip()
def get_file_path(): config_file = "config.json" file_path = ""
if os.path.exists(config_file): with open(config_file, "r", encoding="utf-8") as f: config = json.load(f) file_path = config.get("file_path", "")
while not file_path or not os.path.exists(file_path): if file_path: print("兑换码文件不存在,请手动写入兑换码文件名后重试。") file_path = input("请输入兑换码文件的名称(含后缀):") with open(config_file, "w", encoding="utf-8") as f: config = {"file_path": file_path} json.dump(config, f)
return file_path
def set_window_size(hwnd, width, height): win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, width, height, win32con.SWP_SHOWWINDOW)
def print_author_info(): author_info = """ 作者:lrwy """ print(author_info)
if __name__ == "__main__": hwnd = win32gui.GetForegroundWindow() set_window_size(hwnd, 600, 600)
print_author_info()
file_path = get_file_path()
lines = read_file_lines(file_path)
for line in lines: line = line.strip() if not line: continue
if not is_containing_chinese_or_empty(line): pyperclip.copy(line) line += " 【已复制】"
print(line)
input("按回车继续输出下一行文本:")
print("\n\n") print("兑换码读取完毕")
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
|
python打包脚本
有依赖
1 2 3 4 5 6 7
| @echo off
set /p script_name=请输入要打包的Python脚本文件名(包括扩展名): set /p icon_name=请输入要使用的图标文件名(包括扩展名):
pyinstaller --onefile --add-data "requirements.txt;." --add-data "%script_name%;." --icon=%icon_name% %script_name%
|
无依赖
1 2 3 4 5 6
| @echo off
set /p script_name=请输入要打包的Python脚本文件名(包括扩展名): set /p icon_name=请输入要使用的图标文件名(包括扩展名):
pyinstaller --onefile --add-data "%script_name%;." --icon=%icon_name% %script_name%
|
OBS备份助手
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| @echo off echo ================================================== echo 欢迎使用 OBS 配置备份与恢复工具 echo 本程序仅支持安装版WinRAR echo 作者: lrwy echo 版本: 0.1r echo ================================================== :menu echo. echo 请选择操作: echo 1. 备份 OBS 配置 echo 2. 恢复 OBS 配置 echo 3. 退出 echo. set /p choice=请输入选项(1、2 或 3):
if "%choice%"=="1" ( call :backup_obs_config ) else if "%choice%"=="2" ( call :restore_obs_config ) else if "%choice%"=="3" ( exit /b ) else ( echo 无效选项,请输入 1、2 或 3。 goto menu )
goto menu
:backup_obs_config echo ================================================== echo 正在备份 OBS 配置... echo ================================================== set "OBS_DIR=%APPDATA%\obs-studio" set "CURRENT_DIR=%~dp0"
for %%A in ("%OBS_DIR%") do set "OBS_FOLDER_NAME=%%~nxA" set "ARCHIVE_NAME=%OBS_FOLDER_NAME%.zip"
if exist "%ProgramFiles%\WinRAR\WinRAR.exe" ( set "COMPRESSOR=%ProgramFiles%\WinRAR\rar.exe" set "COMPRESSOR_NAME=WinRAR" ) else ( echo 错误: 未找到 WinRAR,请安装 WinRAR 后再运行此脚本。 pause exit /b )
if not exist "%OBS_DIR%" ( echo 错误: 未找到 OBS Studio 文件夹。 pause exit /b )
"%COMPRESSOR%" a -ep1 -r "%CURRENT_DIR%%ARCHIVE_NAME%" "%OBS_DIR%" if %errorlevel% neq 0 ( echo 备份失败。 ) else ( echo OBS Studio 文件夹已成功压缩为 %ARCHIVE_NAME%,使用 %COMPRESSOR_NAME% 进行压缩。 )
goto menu
:restore_obs_config echo ================================================== echo 正在恢复 OBS 配置... echo ================================================== for /f "tokens=3 delims=\" %%a in ("%userprofile%") do set "USERNAME=%%a" set "ROAMING_DIR=C:\Users\%USERNAME%\AppData\Roaming"
if exist "%ProgramFiles%\WinRAR\WinRAR.exe" ( set "EXTRACTOR=%ProgramFiles%\WinRAR\rar.exe" set "EXTRACTOR_NAME=WinRAR" ) else ( echo 错误: 未找到 WinRAR,请安装 WinRAR 后再运行此脚本。 pause exit /b )
cd /d "%ROAMING_DIR%" "%EXTRACTOR%" x -o"%ROAMING_DIR%" "%~dp0*.zip"
if %errorlevel% neq 0 ( echo 恢复失败。 ) else ( echo 备份已成功恢复到 %ROAMING_DIR%,使用 %EXTRACTOR_NAME% 进行解压。 )
goto menu
|