Last active
May 5, 2020 19:38
-
-
Save mikesname/fca11a2d876b16b0f056aa8a4a8d5e5d to your computer and use it in GitHub Desktop.
Processing data from GraphQL to CSV. Install the ijson module first.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import csv, ijson, sys | |
items = ijson.items(sys.stdin, "data.documentaryUnits.items.item") | |
csvout = csv.writer(sys.stdout, quoting = csv.QUOTE_MINIMAL) | |
for item in items: | |
for description in item["descriptions"]: | |
row = [ | |
description["scopeAndContent"], | |
description["biographicalHistory"], | |
description["systemOfArrangement"]] | |
if [r for r in row if r is not None]: | |
csvout.writerow([item["id"]] + row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query documentaryUnitData { | |
documentaryUnits { | |
items { | |
id | |
descriptions { | |
languageCode | |
biographicalHistory | |
scopeAndContent | |
systemOfArrangement | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment