36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
''' move to class kmanWindow kmanapp.py
|
|
XXX
|
|
def export_notes(self, bks, fnpref, ft='MD'):
|
|
"""format output and write to file
|
|
markdown format:
|
|
TYPE | bookname | author | marktime | content
|
|
--|--|--|--|--
|
|
xx|xx|xx|xx|xx
|
|
|
|
CSV format:
|
|
TYPE,bookname,author,marktime,content
|
|
xx,xx,xx,xx,xx
|
|
|
|
marktime: 20200403 PM 3:0:3 星期五
|
|
|
|
Args:
|
|
bks: books dict
|
|
f: can be 'MD'/'JSON'/'CSV'
|
|
|
|
Returns: special format of 'bks' dict
|
|
"""
|
|
|
|
suff = {'MD':'.md','CSV':'.csv','JSON':'.json'}
|
|
op = fnpref+suff[ft]
|
|
|
|
with open(op, 'w', encoding='utf8', errors='ignore') as fw:
|
|
if ft=='JSON':
|
|
fw.write(json.dumps(bks, indent=4, sort_keys=True, ensure_ascii=False))
|
|
elif ft in ['MD','CSV']:
|
|
for s in self.format_note_data(bks, ft):
|
|
fw.write(s)
|
|
fw.write('\n')
|
|
else:
|
|
fw.write(json.dumps(bks)) # only for load back
|
|
'''
|