将数据处理脚本从硬编码路径改为配置驱动的路径管理,支持多账号批量处理。
原始数据目录保持不变,只新增 how解构/ 输出目录:
data/账号/阿里多多酱/
├── what解构/ # 原始数据(不动)
├── what解构_所有帖子/ # 原始数据(不动)
├── pattern/ # 原始数据(不动)
│ └── cluster/
│ └── clustered_data.json
└── how解构/ # 新增:所有输出结果
├── intermediate/ # 中间结果
│ ├── 特征名称_分类映射.json
│ ├── 分类层级映射.json
│ ├── 特征名称_帖子来源.json
│ └── 当前帖子_解构任务列表.json
├── results/ # how解构最终结果
│ └── *_how.json
└── visualization/ # 可视化结果
└── how解构结果_可视化.html
| 文件类型 | 旧路径 | 新路径 |
|---|---|---|
| pattern聚合结果 | data/data_1118/过去帖子_pattern聚合结果.json |
data/账号/阿里多多酱/pattern/cluster/clustered_data.json |
| 当前帖子what解构 | data/data_1118/当前帖子_what解构结果/ |
data/账号/阿里多多酱/what解构/ |
| 过去帖子what解构 | data/data_1118/过去帖子_what解构结果/ |
data/账号/阿里多多酱/what解构_所有帖子/ |
| 特征分类映射 | data/data_1118/特征名称_分类映射.json |
data/账号/阿里多多酱/how解构/intermediate/特征名称_分类映射.json |
| 分类层级映射 | data/data_1118/分类层级映射.json |
data/账号/阿里多多酱/how解构/intermediate/分类层级映射.json |
| 特征帖子来源 | data/data_1118/特征名称_帖子来源.json |
data/账号/阿里多多酱/how解构/intermediate/特征名称_帖子来源.json |
| 解构任务列表 | data/data_1118/当前帖子_解构任务列表.json |
data/账号/阿里多多酱/how解构/intermediate/当前帖子_解构任务列表.json |
| how解构结果 | data/data_1118/当前帖子_how解构结果/ |
data/账号/阿里多多酱/how解构/results/ |
| 可视化结果 | data/data_1118/当前帖子_how解构结果_可视化.html |
data/账号/阿里多多酱/how解构/visualization/how解构结果_可视化.html |
config/accounts.json - 账号配置文件script/data_processing/path_config.py - 路径配置管理类script/data_processing/run_all_with_config.sh - 支持多账号的运行脚本script/data_processing/migrate_data_structure.sh - 数据迁移脚本(已不需要)script/data_processing/extract_feature_categories.py
from script.data_processing.path_config import PathConfigPathConfig 替代硬编码路径script/data_processing/extract_features_from_posts.py
from script.data_processing.path_config import PathConfigPathConfig 替代硬编码路径script/data_processing/extract_current_posts.py
from script.data_processing.path_config import PathConfigPathConfig 替代硬编码路径script/data_processing/match_inspiration_features.py
from script.data_processing.path_config import PathConfigPathConfig 替代硬编码路径script/data_processing/visualize_how_results.py
from script.data_processing.path_config import PathConfigload_feature_category_mapping() 和 load_feature_source_mapping() 函数接受 PathConfig 参数PathConfig 替代硬编码路径script/data_processing/run_all.sh (旧版本,已更新路径但建议使用新版本)
# 方式1:命令行参数
./script/data_processing/run_all_with_config.sh 阿里多多酱
# 方式2:环境变量
ACCOUNT_NAME=阿里多多酱 ./script/data_processing/run_all_with_config.sh
# 方式3:使用默认账号(配置文件中的 default_account)
./script/data_processing/run_all_with_config.sh
# 处理所有在配置文件中启用的账号
./script/data_processing/run_all_with_config.sh --all
from script.data_processing.path_config import PathConfig
# 获取路径配置
config = PathConfig() # 使用默认账号
# 或
config = PathConfig(account_name="阿里多多酱")
# 使用路径
input_file = config.pattern_cluster_file
output_file = config.feature_category_mapping_file
# 确保输出目录存在
config.ensure_dirs()
# 读写文件
with open(input_file, 'r') as f:
data = json.load(f)
with open(output_file, 'w') as f:
json.dump(result, f)
创建账号目录和原始数据:
mkdir -p "data/账号/新账号名/what解构"
mkdir -p "data/账号/新账号名/what解构_所有帖子"
mkdir -p "data/账号/新账号名/pattern/cluster"
# 放入原始数据...
config/accounts.json 中添加配置:
json
{
"name": "新账号名",
"enabled": true,
"description": "新账号描述"
}
运行处理脚本:
./script/data_processing/run_all_with_config.sh 新账号名
从旧版本迁移到新版本:
data/data_1118/ 下的中间结果和输出文件run_all_with_config.sh 替代 run_all.shhow解构/ 目录run_all.sh 仍可使用(路径已更新)验证配置是否正确:
# 查看路径配置
python script/data_processing/path_config.py 阿里多多酱
# 测试路径并创建输出目录
python -c "from script.data_processing.path_config import PathConfig; config = PathConfig('阿里多多酱'); config.check_and_print_status(); config.ensure_dirs()"
how解构/ 目录及子目录ACCOUNT_NAME 指定账号,方便CI/CD集成