tiddly2kitaab/tiddly2kitaab.py

47 lines
1.2 KiB
Python
Raw Normal View History

2020-10-19 06:48:23 -07:00
import json
def createFile(tiddler):
try:
created = tiddler['created']
except KeyError:
print("!!! BLANK TIDDLER !!!")
print(tiddler)
return
title = tiddler['title']
text = tiddler['text']
modified = tiddler['modified']
tags = tiddler['tags']
# create the filename
filename = created[2:8] # YYMMDD
filename = filename + "-"
2020-10-20 05:55:13 -07:00
hour = title[-5:]
time = hour.replace(':', '')
filename = filename+time+'.wiki'
2020-10-19 06:48:23 -07:00
# handle tags
allTags = ':'
2020-10-20 05:55:13 -07:00
tagList = tags.replace('[', '').replace(']', '').split(' ') # Ugly one liner
for t in tagList:
if t == 'Journal':
t = 'jrnl'
2020-10-19 06:48:23 -07:00
allTags = allTags + t + ':'
# handle date
date = created[:4] + '-' + created[4:6] + '-' + created[6:8] + ' ' + hour
# create write list
2020-10-20 05:55:13 -07:00
writeList = ['%title {}\n'.format(title), allTags, '\n', '%date {}\n'.format(date), '\n', text]
2020-10-19 06:48:23 -07:00
# create and write the file
file = open('./jrnl/'+filename, 'w+')
file.writelines(writeList)
file.close()
def createFiles(tiddlers):
for t in tiddlers:
createFile(t)
tid = json.load(open('tiddlers.json'))
createFiles(tid)