Skip to content

Commit

Permalink
additional_data: commands: Add additional_data_tool
Browse files Browse the repository at this point in the history
Create a little tool to run files through the additional_data generator.

Usage ./mange.py additional_data_tool example-grants.json

This will write/overwrite an `additional_data` object into the grant
object(s).
  • Loading branch information
michaelwood committed Mar 25, 2021
1 parent 4a00c52 commit 0215a3c
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json

from django.core.management.base import BaseCommand

from additional_data.generator import AdditionalDataGenerator


class Command(BaseCommand):
help = "Writes the additional_data object to ThreeSixtyGiving grant data JSON file"

def add_arguments(self, parser):
parser.add_argument(
type=str,
action="store",
dest="grants_file",
help="The JSON file that contains an array of ThreeSixtyGiving grant data",
)

def handle(self, *args, **options):

with open(options["grants_file"]) as grants_file:
grants_json = json.load(grants_file)

generator = AdditionalDataGenerator()

for grant in grants_json["grants"]:
additional_data = generator.create(grant)
grant["additional_data"] = additional_data

with open(options["grants_file"], "w") as grants_file:
json.dump(grants_json, grants_file, indent=2)

0 comments on commit 0215a3c

Please sign in to comment.