spellbook/make_tiddlers.py
2022-03-22 11:45:11 +10:00

70 lines
1.8 KiB
Python

import json
'''
json format to import tiddlers:
[
{
"text":
"title":
"tags":
"modified": yyyymmdd xxxxxxxxx (x = milliseconds)
"created": (as above)
}
]
'''
# all data for json.dumps
da = []
jrnl = open("/home/anish/scratch/jrnl.md", "r")
data = {}
for line in jrnl:
'''
TODO
change date to format XXth of MMM at HH:MM??
import into tiddly wiki
'''
if not line in ('\n', '\r\n'):
if not (line[0].isalpha()):
data["tags"] = "Journal"
data["title"] = line
#get rid of all extra characters
line = line.translate(None, ': -am')
# have to deal with am/pm
pm = False
if line[-1] == 'p':
pm = True
line = line.translate(None, 'p')
# format into: yyyymmdd xxxxxxxxx
years = "20" + line[4:6]
month = line[2:4]
day = line[0:2]
hours = line[-5:-3]
if pm:
hours = int(hours) + 12
mins = line[-3:-1]
# there's 2 errors -- after 20171026
print(years+month+day)
# milliseconds for the xxx...
milli = str(3600000 * int(hours) + 60000 * int(mins))
# format to the same length (10)
if len(milli) < 9:
milli = "0" + milli
createtime = years+month+day+milli
data["created"] = createtime
data["modified"] = createtime
else:
data["text"] = line
da.append(data)
# per tiddler entry in a dict
# so must reset data once the text has been added
data = {}
output = open("jrnl.json", 'w')
output.write(json.dumps(da, sort_keys=True))