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)
|