Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jiushill authored Jul 26, 2020
1 parent cabb7ad commit 78ca1fb
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 自己写的工具/印象笔记分类导出/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 印象笔记enex分类导出 ##
由于国际局势不稳定,说不定那天厂商就完蛋了。印象笔记又不搞个自动按照标签导出分类,只能自己写了

使用方式:
```python
FILEPATH=r"C:\Users\JiuShi\Desktop\Evernote [2].enex" #单个文件或文件夹路径
OUTPUTFILE=r"C:\Users\JiuShi\Desktop\output"
NUMBER=500 #信息量过大时,数量到一定程度并发
```

导出结果如下
![](img/1.png)

![](img/2.png)

3 changes: 3 additions & 0 deletions 自己写的工具/印象笔记分类导出/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FILEPATH=r"C:\Users\JiuShi\Desktop\Evernote.enex" #单个文件或文件夹路径
OUTPUTFILE=r"C:\Users\JiuShi\Desktop\output"
NUMBER=500 #信息量过大时,数量到一定程度并发
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions 自己写的工具/印象笔记分类导出/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
from gevent import monkey;monkey.patch_all()
from bs4 import BeautifulSoup
import json
import re
import os
import sys
import config
import xmltodict
import gevent

def xmltojson(xmldata):
xmlparse=xmltodict.parse(xmldata)
jsondata=json.dumps(xmlparse,indent=1)
data=json.loads(jsondata)
export=data["en-export"]
note=export["note"]
temps=[]
if isinstance(note,list)==True:
for d in note:
temps.append(gevent.spawn(chuli,d,export))
if len(temps)==config.NUMBER:
gevent.joinall(temps)
temps.clear()
else:
chuli(note,export)

if len(temps)>0:
gevent.joinall(temps)
temps.clear()

def chuli(note,export):
createnotetime="{}".format(export["@export-date"]).split("T")
createnotetime="{}年{}月{}日 {}:{}".format(createnotetime[0][0:-4],createnotetime[0][-4:-2],createnotetime[0][-2::],createnotetime[1][0:2],createnotetime[1][2:4])
version=export["@version"]
application=export["@application"]
title=note["title"]
if "tag" in [x for x in note]:
tag=note["tag"]
else:
tag="None"
autor=note["note-attributes"]["author"]
content=note["content"]
if "resource" in [x for x in note]:
resure=note["resource"]
else:
resure=""

en=re.findall('<en-media hash=".*?"/>',content)
# print(en)

'''获取图片base64'''
texts=[]
for e in en:
hashs=BeautifulSoup(e,"html.parser").find_all("en-media")[0].get("hash")
if isinstance(resure,list)==True:
for j in resure:
# print(j,file=open("axc.txt","a",encoding="utf-8"))
try:
id=j["recognition"]
if hashs in id:
text = j["data"]["#text"]
texts.append(text)
except:
text = j["data"]["#text"]
texts.append(text)
else:
text = resure["data"]["#text"]
texts.append(text)

try:
for e in range(0,len(en)):
#print(en[e],texts[e])
if "width" in en[e]:
width = re.findall('width=".*"',en[e])[0]
content = str(content).replace(en[e], '<img src="data:image/jpg;base64,{}" {}>'.format(texts[e],width))
else:
content=str(content).replace(en[e],'<img src="data:image/jpg;base64,{}">'.format(texts[e]))
except:
pass

htmldata='''<html>
<head>
<title>{}</title>
</head>
<body>
<b>作者:{}</b><br>
<b>时间:{}</b><br>
<b>使用系统:{}</b><br>
<b>印象笔记版本:{}</b><br>
<b>标签:{}</b><br>
{}
</body>
</html>
'''.format(title,autor,createnotetime,application,version,tag,content)

pths="{}{}".format(outpath,tag)
if os.path.exists(pths)==False:
os.mkdir(pths)

for t in ["?","*"':','"',"<",">","\\","/","|"]:
if t in title:
title=str(title).replace(t,"")

paths="{}{}{}.html".format(pths,pcth,title)
print(htmldata,file=open("{}".format(paths),"a",encoding="utf-8"))
print("[+] {} dump file ok".format(paths))

if __name__ == '__main__':
path=config.FILEPATH
outpath = str(config.OUTPUTFILE).rstrip("\\").rstrip("/")
if sys.platform == "win32":
pcth="\\"
outpath += "\\"
else:
pcth="/"
outpath += "/"

if os.path.exists(outpath)==False:
os.mkdir(outpath)
if os.path.exists(path):
if os.path.isfile(path):
xmltojson(open("{}".format(path),"r",encoding="utf-8").read())
else:
paths_=os.walk(path)
temp=[]
for i in paths_:
for f in i[-1]:
pach = "{}{}{}".format(i[0], pcth,f)
temp.append(gevent.spawn(xmltojson,open("{}".format(pach),"r",encoding="utf-8").read()))
if len(temp)==config.NUMBER:
gevent.joinall(temp)
temp.clear()

if len(temp)>0:
gevent.joinall(temp)
temp.clear()

0 comments on commit 78ca1fb

Please sign in to comment.