glossari: retocs
[apunts-acces-uib-majors-25-anys-matematiques.git] / tb2md.py
blobaf9e8fb7ddd37c6700cd8024cf0a3599e68c6a91
1 #!/usr/bin/env python
3 # SPDX-FileCopyrightText: 2023 Xavier Bordoy
5 # SPDX-License-Identifier: GPL-3.0-or-later
7 # tb2md
8 # Taskboard to Markdown
9 # This program is to pass information from taskboard JSON file [https://github.com/mickael-menu/zk]
10 # to markdown [https://commonmark.org/]
12 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
16 import json
17 fitxer = "tasques/taskbook/storage/storage.json"
19 ## Import JSON taskboard file
20 with open(fitxer) as f:
21 contents = f.read()
23 j = json.loads(contents)
25 ## Export Hash as List of tasks
26 tasks = []
28 for k in j.keys():
29 tasks.append(j[k])
31 ## Know the boards
32 ### A task could has several boards
33 sboards = [t['boards'] for t in tasks]
34 boards = []
35 for b in sboards:
36 for v in b:
37 boards.append(v)
39 # So the boards is the sorted boards along all tasks
40 boards = sorted(list(set(boards)))
42 ## Export as markdown
43 ## Just incompleted tasks
44 msg = "# Versions \n\n"
46 for b in boards:
47 msg = msg + "\n## " + b[1:] + " \n\n"
49 tasksinb = [t for t in tasks if b in t['boards'] and t['_isTask'] == True and t['isComplete'] == False]
50 notesinb = [t for t in tasks if b in t['boards'] and t['_isTask'] == False]
52 # First display notes
54 if notesinb:
55 msg = msg + "### Notes \n\n"
57 for n in notesinb:
58 msg = msg + "- [#{_id}] {description}\n".format(_id = n['_id'], description=n['description'])
60 # Separation
61 msg = msg + "\n"
63 # Then tasks
64 if len(tasksinb) > 0:
65 msg = msg + "### Tasques \n\n"
67 for t in tasksinb:
68 msg = msg + "- [#{_id}] {description} \n".format(_id = t['_id'], description = t['description'])
70 print(msg)