katex -> mathjax
[exercicis-automatics-matematiques.git] / tb2md.py
blob35ee80bedc0ccfd9c8cd5a41bd94b1cf09520ac9
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/klaudiosinani/taskbook] to markdown [https://commonmark.org/]
11 # 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.
12 # 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.
13 # You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
15 import json
16 tbfile = "tasques/taskbook/storage/storage.json"
18 ## Import JSON taskboard file
19 with open(tbfile) as f:
20 contents = f.read()
22 j = json.loads(contents)
24 ## Export Hash as List of tasks
25 tasks = []
27 for k in j.keys():
28 tasks.append(j[k])
30 ## Know the boards
31 ### A task could has several boards
32 sboards = [t['boards'] for t in tasks]
33 boards = []
34 for b in sboards:
35 for v in b:
36 boards.append(v)
38 # So the boards is the sorted boards along all tasks
39 boards = sorted(list(set(boards)))
41 ## Export as markdown
42 ## Just incompleted tasks
43 msg = "# Fites \n\n"
45 for b in boards:
46 msg = msg + "\n## " + b[1:] + " \n\n"
48 tasksinb = [t for t in tasks if b in t['boards'] and t['_isTask'] == True and t['isComplete'] == False]
49 notesinb = [t for t in tasks if b in t['boards'] and t['_isTask'] == False]
51 # First display notes
53 if notesinb:
54 msg = msg + "### Notes \n\n"
56 for n in notesinb:
57 msg = msg + "- [#{_id}] {description}\n".format(_id = n['_id'], description=n['description'])
59 # Separation
60 msg = msg + "\n"
62 # Then tasks
63 if len(tasksinb) > 0:
64 msg = msg + "### Tasques \n\n"
66 for t in tasksinb:
67 msg = msg + "- [#{_id}] {description} \n".format(_id = t['_id'], description = t['description'])
69 print(msg)