Skip to content

Instantly share code, notes, and snippets.

@pangda0xff
Created August 31, 2019 15:42
Show Gist options
  • Save pangda0xff/274be2f416348bc8805458bb691411f9 to your computer and use it in GitHub Desktop.
Save pangda0xff/274be2f416348bc8805458bb691411f9 to your computer and use it in GitHub Desktop.
有道云笔记脑图转换为百度脑图
import simplejson as json
from sys import argv
from codecs import open
def read_all_nodes(file):
with open(file, 'r', 'utf-8') as f:
result = f.read()
root = json.loads(result)
return root["nodes"]
def write_nodes(nodes, current, deep, file):
children = [n for n in nodes if n["parentid"] == current]
if len(children) > 0:
for child in children:
file.write("\t" * deep)
file.write(child["topic"])
file.write("\n")
write_nodes(nodes, child["id"], deep + 1, file)
if __name__ == "__main__":
nodes = read_all_nodes(argv[1])
root = [n for n in nodes if n["isroot"]][0]
with open("output.txt", "w", "utf-8") as f:
f.write(root["topic"])
f.write("\n")
write_nodes(nodes,root["id"],1,f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment