2026-03-31 17:18:30 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
"""
|
|
|
|
|
|
独立命令行导入脚本。
|
|
|
|
|
|
|
|
|
|
|
|
用法:
|
|
|
|
|
|
python run_import.py # 增量导入(MERGE,不删除现有数据)
|
|
|
|
|
|
python run_import.py --clear # 清空图谱后全量重新导入
|
2026-04-01 15:55:53 +08:00
|
|
|
|
python run_import.py ldj # 仅导入鹿鼎记
|
|
|
|
|
|
python run_import.py dtslz tlbb --clear # 清空后导入指定小说
|
2026-03-31 17:18:30 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
from graph_query import get_driver
|
2026-04-01 15:55:53 +08:00
|
|
|
|
from graph_builder import build_all_graphs, SUPPORTED_NOVELS
|
2026-03-31 17:18:30 +08:00
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
clear = "--clear" in sys.argv
|
2026-04-01 15:55:53 +08:00
|
|
|
|
novels = [arg for arg in sys.argv[1:] if not arg.startswith("--")]
|
|
|
|
|
|
selected = novels or list(SUPPORTED_NOVELS)
|
2026-03-31 17:18:30 +08:00
|
|
|
|
|
|
|
|
|
|
print("Connecting to Neo4j...")
|
|
|
|
|
|
driver = get_driver()
|
|
|
|
|
|
driver.verify_connectivity()
|
|
|
|
|
|
print("Connected.\n")
|
|
|
|
|
|
|
2026-04-01 15:55:53 +08:00
|
|
|
|
build_all_graphs(driver, novels=selected, clear=clear)
|
2026-03-31 17:18:30 +08:00
|
|
|
|
|
|
|
|
|
|
print("\nGraph stats:")
|
|
|
|
|
|
from graph_query import get_graph_stats
|
|
|
|
|
|
for k, v in get_graph_stats().items():
|
|
|
|
|
|
print(f" {k}: {v}")
|
|
|
|
|
|
|
|
|
|
|
|
driver.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
main()
|