import os with open('/Users/liruojuan/Library/CloudStorage/OneDrive-个人/Code/Python/Flask App/成绩查询/templates/login.html', 'r', encoding='utf-8') as f: text = f.read() text = text.replace( 'if (data.has_qr) {', '''window.lastQrUpdate = window.lastQrUpdate || 0; if (data.has_qr && data.status === 'waiting_login') {''' ) text = text.replace( '''qrImg.src = `/static/dingtalk_qr.png?t=${Date.now()}`;''', '''if (!qrImg.src || qrImg.src.indexOf('static/dingtalk_qr.png') === -1 || (Date.now() - window.lastQrUpdate > 3000)) { qrImg.src = `/static/dingtalk_qr.png?t=${Date.now()}`; window.lastQrUpdate = Date.now(); }''' ) text = text.replace( '''qrPlaceholder.style.display = 'none';\n }''', '''qrPlaceholder.style.display = 'none'; } else { qrImg.style.display = 'none'; qrImg.src = ''; qrPlaceholder.style.display = 'flex'; qrPlaceholder.innerHTML = '' + (data.status === "done" ? "登录已完成" : (isError ? "抓取异常" : "暂无二维码")) + ''; }''' ) with open('/Users/liruojuan/Library/CloudStorage/OneDrive-个人/Code/Python/Flask App/成绩查询/templates/login.html', 'w', encoding='utf-8') as f: f.write(text)