fix_user_id.py 880 B

1234567891011121314151617181920212223242526272829303132333435
  1. import re
  2. import os
  3. # 获取脚本所在目录
  4. script_dir = os.path.dirname(os.path.abspath(__file__))
  5. # 需要修复的文件列表
  6. files_to_fix = [
  7. 'routers/chat.py',
  8. 'routers/scene.py',
  9. 'routers/hazard.py'
  10. ]
  11. for file_path in files_to_fix:
  12. full_path = os.path.join(script_dir, file_path)
  13. if not os.path.exists(full_path):
  14. print(f'文件不存在: {full_path}')
  15. continue
  16. print(f'正在修复: {file_path}')
  17. # 读取文件
  18. with open(full_path, 'r', encoding='utf-8') as f:
  19. content = f.read()
  20. # 替换所有 user.user_id 为 user.userCode
  21. new_content = re.sub(r'user\.user_id', 'user.userCode', content)
  22. # 写回文件
  23. with open(full_path, 'w', encoding='utf-8') as f:
  24. f.write(new_content)
  25. print(f'✓ {file_path} 修复完成')
  26. print('\n所有文件修复完成!')