# 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