diff --git a/jrnl-merge b/jrnl-merge deleted file mode 120000 index f9a50ce..0000000 --- a/jrnl-merge +++ /dev/null @@ -1 +0,0 @@ -/home/anish/usr/dev/jrnl-merger/run.sh \ No newline at end of file diff --git a/jrnl-merge/jrnlFix.py b/jrnl-merge/jrnlFix.py new file mode 100644 index 0000000..19ecb8c --- /dev/null +++ b/jrnl-merge/jrnlFix.py @@ -0,0 +1,144 @@ +# some code imported from https://github.com/ng110/TiddlPy/blob/master/TiddlPy/TiddlPy.py + +import re +import shutil +from time import strftime, gmtime +import json +from bs4 import BeautifulSoup +from os import listdir +from os.path import isfile, join + + +def tid2dict(tiddler): + """ + tid2dict(tiddler) + Converts tiddler as a BeautifulSoup object into a Python dictionary + """ + tiddict = tiddler.attrs + tiddict[u'text'] = tiddler.text + return tiddict + + +def openTiddlers(file): + twsoup = BeautifulSoup(file, 'html.parser') + storearea = twsoup.find('div', id="storeArea") + tiddlers = storearea('div') + ori_matched_tiddlers = [] + + for tid in tiddlers: + # this is wrong, it only keeps the last/final tiddler it reads + ori_matched_tiddlers.append(tid2dict(tid)) + return ori_matched_tiddlers + + +def wikiedit(wiki, tiddlers, deletelist, modi=u'python'): + # Try and figure out how this works so you can debug it + # so far it's pretty robust + """ + wiki is the wikifilename. + Deletes tiddlers in the deletelist and the tiddlers list, if they currently + exist, then writes the tiddlers list, adding/replacing the modifier + attribute with the specified or default value. Timestamps modified and/or + created dates in UTC. + Returns (writtenlist, deletedlist) - list of tiddlers successfully deleted + and written. + """ + encoding = 'utf-8' + savelist = [] + writtenlist = [] + deletedlist = [] + created = {} + for tid in tiddlers: + savelist.append(tid[u'title']) + with open(wiki, 'br') as fhi, open('temp__.html', 'bw') as fho: + for line in fhi: + if re.search('^
{}\n