corrected error for tb2md
[soltea.git] / tb2md.py
blob0206b47d3cfffa51f0e41c0f5b0709a92f11b4c4
1 #!/usr/bin/env python
2 # tb2md
3 # Taskboard to Markdown
4 # This program is to pass information from taskboard JSON file [https://github.com/klaudiosinani/taskbook] to markdown [https://commonmark.org/]
6 # 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.
7 # 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.
8 # You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
10 import json
11 import argparse
12 import os.path
14 def convert(tbfile):
16 # Import JSON taskboard file
17 with open(tbfile) as f:
18 contents = f.read()
20 j = json.loads(contents)
22 # Export Hash as List of tasks
23 tasks = []
25 for k in j.keys():
26 tasks.append(j[k])
28 # Know the boards
29 ## A task could has several boards
30 sboards = [t['boards'] for t in tasks]
31 boards = []
32 for b in sboards:
33 for v in b:
34 boards.append(v)
36 # So the boards is the sorted boards along all tasks
37 boards = sorted(list(set(boards)))
39 ## Export as markdown
40 ## Just incompleted tasks
41 msg = "# Versions \n\n"
43 for b in boards:
44 msg = msg + "\n## " + b[1:] + " \n\n"
46 tasksinb = [t for t in tasks if b in t['boards'] and t['_isTask'] == True and t['isComplete'] == False]
47 notesinb = [t for t in tasks if b in t['boards'] and t['_isTask'] == False]
49 #First display notes
50 if notesinb:
51 msg = msg + "### Notes \n\n"
53 for n in notesinb:
54 msg = msg + "- [#{_id}] {description}\n".format(_id = n['_id'], description=n['description'])
56 # Separation
57 msg = msg + "\n"
59 # Then tasks
60 if len(tasksinb) > 0:
61 msg = msg + "### Tasks \n\n"
63 for t in tasksinb:
64 msg = msg + "- [#{_id}] {description} \n".format(_id = t['_id'], description = t['description'])
66 print(msg)
70 # Parse program arguments
71 parser = argparse.ArgumentParser(description="Convert tarkboard JSON file to markdown")
72 parser.add_argument("json", type=str, help="JSON file to convert")
73 args = parser.parse_args()
75 if args.json:
76 if os.path.exists(args.json):
77 convert(args.json)
78 else:
79 print("Error. No JSON file to convert provided")