write json to specified output dir instead of current directory
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 30 Aug 2022 03:52:53 +0000 (20:52 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Tue, 30 Aug 2022 03:52:53 +0000 (20:52 -0700)
src/budget_sync/main.py

index d2674b584b057a1d4900bd1a0ef56fe8c16debd4..cdcc82edc8413e81d8428e1572855f5290cba1ea 100644 (file)
@@ -69,7 +69,7 @@ def main():
         write_budget_markdown(budget_graph, args.output_dir)
         write_budget_csv(budget_graph, args.output_dir)
     summarize_milestones(budget_graph)
-    json_milestones(budget_graph, args.comments)
+    json_milestones(budget_graph, args.comments, args.output_dir)
 
 
 def print_markdown_for_person(budget_graph: BudgetGraph, config: Config,
@@ -136,7 +136,8 @@ def summarize_milestones(budget_graph: BudgetGraph):
     print ("```") # for using the output as markdown
 
 
-def json_milestones(budget_graph, add_comments):
+def json_milestones(budget_graph: BudgetGraph, add_comments: bool,
+                    output_dir: Path):
     """reports milestones as json format
     """
     for milestone, payments in budget_graph.milestone_payments.items():
@@ -181,8 +182,8 @@ def json_milestones(budget_graph, add_comments):
                 comments = child.bug.getcomments()
                 comment += "\n%s" % comments[0]['text']
             intro.append(comment)
-            #print (description, intro)
-            sys.stdout.flush()
+            # print (description, intro)
+            sys.stdout.flush()
             task = {'title': "%d %s" % (child.bug.id, child.bug.summary),
                     'intro': intro,
                     'amount': child.fixed_budget_including_subtasks.int(),
@@ -201,8 +202,8 @@ def json_milestones(budget_graph, add_comments):
                      }
              }
 
-        with open("report.%s.json" % milestone.identifier, "w") as f:
-            json.dump(d, f, indent=2)
+        output_file = output_dir / f"report.{milestone.identifier}.json"
+        output_file.write_text(json.dumps(d, indent=2), encoding="utf-8")