From 9939101247bc3ce10e9ef9e49e4c82860559efa1 Mon Sep 17 00:00:00 2001 From: James Turk Date: Fri, 14 Feb 2020 14:01:30 -0500 Subject: [PATCH] output json from export_history --- bulk/management/commands/export_history.py | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bulk/management/commands/export_history.py b/bulk/management/commands/export_history.py index 62501e80..d4254504 100644 --- a/bulk/management/commands/export_history.py +++ b/bulk/management/commands/export_history.py @@ -1,3 +1,4 @@ +import json from functools import lru_cache from collections import defaultdict from django.core.management.base import BaseCommand @@ -154,9 +155,24 @@ def handle_epoch(**kwargs): # TODO: handle subobjects for bill_id, changes in changes["bill"].items(): change_obj = make_change_object(changes) - from pprint import pprint + yield change_obj + # for vote_id, changes in changes["vote"].items(): + # change_obj = make_change_object(changes) + # yield change_obj + + +def output_json(epoch, data): + output = { + "version": "0.1", + "source": "https://openstates.org", + "epoch": epoch, + "changes": [], + } + for item in data: + output["changes"].append(item) - pprint(change_obj) + with open(f"changelog_{epoch}.json", "w") as f: + json.dump(output, f, indent=1) class Command(BaseCommand): @@ -170,4 +186,5 @@ def handle(self, *args, **options): "event_time__hour", "event_time__minute", ).distinct(): - handle_epoch(**time) + formatted = format_time(**time) + output_json(formatted, handle_epoch(**time))