Infine ho fatto questo:
import re
import collections
import yaml
def t2k(file):
with open(file)as f:
txt=f.read()
regex=r"(?sm)\* (.*?) :(\s+-.*?)(?=^\*|\Z)"
regactions=r' - ([^\#]*)(?P<status>#.) (\[.*])'
# list of topics with action and status
topics=re.finditer(regex,txt,re.MULTILINE)
# Initiate kanban liste
list_kanban=[]
for topic in topics:
#parse action in topics
actions=re.finditer(regactions,topic[2])
for action in actions:
# create a kanban for each action
kanban={'topic':topic[1], 'actions':action[1]}
list_kanban.append({action['status'][-1:]:kanban})
# group list kanban by status
dict_kanban = collections.defaultdict(list)
for d in list_kanban:
for k, v in d.items():
dict_kanban[k].append(v)
result=[]
for statut in dict_kanban.keys():
single_topic=[]
topi_dict={}
for d in dict_kanban[statut]:
if d['topic'] not in single_topic:
single_topic.append(d['topic'])
topi_dict[d['topic']]=[d['actions']]
else:
topi_dict[d['topic']].append(d['actions'])
result.append({statut:topi_dict})
#%%
ff = open('PDCA.yaml', 'w+')
yaml.dump(result, ff, allow_unicode=True, default_flow_style=False,sort_keys=False)
print('-')
print(result)
return result
E lo si utilizza in questo modo:
import PDCA
PDCA.t2k('txt.md')
with open('PDCA.yaml') as f:
print(f.read())
Abbastanza sicuro che non è il modo più divinatorio, ma non il lavoro. Il passo successivo sarebbe quello di avere un editor web in diretta che avrebbe trasformata di kanban PDCA come si sta prendendo appunti .... chiedevo se avrei usato flexx o remi, ma questa è un'altra storia