Finalmente hice esto:
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
Y se utiliza de esta manera:
import PDCA
PDCA.t2k('txt.md')
with open('PDCA.yaml') as f:
print(f.read())
Bastante seguro de que no es la forma más Pythonic pero hace el trabajo. El siguiente paso sería tener un editor web en vivo que tranformar el Kanban PDCA como usted está tomando notas .... preguntaba si me gustaría utilizar flexx o Remi, pero eso es otra historia