Skip to content

Instantly share code, notes, and snippets.

@minorua
Created December 21, 2023 07:08
Show Gist options
  • Save minorua/d3c4972f451267d0dd71ad41b8c831e7 to your computer and use it in GitHub Desktop.
Save minorua/d3c4972f451267d0dd71ad41b8c831e7 to your computer and use it in GitHub Desktop.
Evernoteからエクスポートされるenexファイルの「無題のノート」のタイトルをコンテンツの1行目の文字列で置き換えるスクリプト
import sys
from xml.dom import minidom
filename = sys.argv[1]
print("Parsing " + filename)
dom = minidom.parse(filename)
notes = dom.getElementsByTagName("note")
for note in notes:
titleNode = note.getElementsByTagName("title")[0].firstChild
title = titleNode.nodeValue
if title != "無題のノート":
print(title)
continue
content = note.getElementsByTagName("content")[0]
data = content.childNodes[1].nodeValue
title = data.split("</div>")[0].split(">")[-1].strip() or "無題のノート"
titleNode.nodeValue = title
print("無題のノート ->" + title)
with open("Replaced\\" + filename, "w", encoding="utf-8") as f:
dom.writexml(f, indent=" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment