chore: 批量更新脚本与数据处理优化
1. 调整database.py批量处理记录数为400 2. 新增convert_available.py用于将available字段的JSON数组格式转换为逗号分隔字符串 3. 更新test.py为数据库查询导出脚本 4. 生成并更新SQL更新语句文件 5. 修正jupyter notebook中的数据库连接配置与代码逻辑
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import re
|
||||
import json
|
||||
|
||||
input_file = '/app/project/python----/数据库/update_statements.sql'
|
||||
output_file = '/app/project/python----/数据库/update_statements_converted.sql'
|
||||
|
||||
with open(input_file, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
lines = content.split('\n')
|
||||
new_lines = []
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line or line.startswith('--'):
|
||||
new_lines.append(line)
|
||||
continue
|
||||
|
||||
# 提取 available 的值(JSON数组格式)
|
||||
match = re.search(r"available='(\[.*?\])'", line)
|
||||
if match:
|
||||
json_str = match.group(1)
|
||||
try:
|
||||
arr = json.loads(json_str)
|
||||
# 用逗号连接
|
||||
joined = ','.join(arr)
|
||||
# 替换原 available 值
|
||||
new_line = line.replace(f"available='{json_str}'", f"available='{joined}'")
|
||||
new_lines.append(new_line)
|
||||
except json.JSONDecodeError:
|
||||
new_lines.append(line)
|
||||
else:
|
||||
new_lines.append(line)
|
||||
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(new_lines))
|
||||
|
||||
print(f"转换完成,输出到: {output_file}")
|
||||
Reference in New Issue
Block a user