Commit 3bca32ca by Shirley He

format json correctly

parent 5b0ce9a9
......@@ -8,6 +8,7 @@ from pprint import pprint
from itertools import product
from itertools import permutations
import sys
import json
def parse_field_arguments():
......@@ -43,23 +44,48 @@ def parse_field_arguments():
for permutation_choices in num_args.fields:
for i in range(0, field_length):
fields[permutation_choices[i]] = permutation_data[permutation_choices[i]]
# for j in range(field_length, total_num_fields):
# fields[permutation_choices[j]] =
# print permutation_data.keys() not in permutation_choices
# for j in range(field_length, total_num_fields):
# fields[permutation_choices[j]] =
# print permutation_data.keys() not in permutation_choices
return fields
def generate_permutations(fields):
# def generate_permutations(fields):
# field_permutations = list(product(*fields.values()))
# #print field_permutations
#
# print fields
#
# # make JSON output file
# with open("test_courses.json", "w") as outfile:
# json.dump(fields, outfile)
field_permutations = list(product(*fields.values()))
def generate_permutations(fields, index, results, current):
allKeys = fields.keys()
optionKey = allKeys[index]
# make JSON output file
with open("test_courses.json", "w") as outfile:
json.dump(field_permutations, outfile)
values = fields[optionKey]
# print values
for i in range(len(values)):
current[optionKey] = values[i]
if index+1 < len(allKeys):
generate_permutations(fields, index+1, results, current)
print current
results.append(current.copy())
# print results
# print current
with open("test_courses.json", "w") as outfile:
json.dump(results, outfile)
if __name__ == "__main__":
parse_field_arguments()
generate_permutations(parse_field_arguments())
generate_permutations(parse_field_arguments(), 0, [], {})
[["past", true, "past"], ["past", true, "future"], ["past", true, null], ["past", false, "past"], ["past", false, "future"], ["past", false, null], ["past", null, "past"], ["past", null, "future"], ["past", null, null], ["future", true, "past"], ["future", true, "future"], ["future", true, null], ["future", false, "past"], ["future", false, "future"], ["future", false, null], ["future", null, "past"], ["future", null, "future"], ["future", null, null], [null, true, "past"], [null, true, "future"], [null, true, null], [null, false, "past"], [null, false, "future"], [null, false, null], [null, null, "past"], [null, null, "future"], [null, null, null]]
\ No newline at end of file
[
{
"start": "past",
"end": "past",
"display_name": "International Project Management"
},
{
"start": "past",
"end": "past",
"display_name": "Cybersecurity Fundamentals"
},
{
"start": "past",
"end": "past",
"display_name": ""
},
{
"start": "past",
"end": "past",
"display_name": null
},
{
"start": "past",
"end": "past",
"display_name": null
},
{
"start": "past",
"end": "future",
"display_name": "International Project Management"
},
{
"start": "past",
"end": "future",
"display_name": "Cybersecurity Fundamentals"
},
{
"start": "past",
"end": "future",
"display_name": ""
},
{
"start": "past",
"end": "future",
"display_name": null
},
{
"start": "past",
"end": "future",
"display_name": null
},
{
"start": "past",
"end": null,
"display_name": "International Project Management"
},
{
"start": "past",
"end": null,
"display_name": "Cybersecurity Fundamentals"
},
{
"start": "past",
"end": null,
"display_name": ""
},
{
"start": "past",
"end": null,
"display_name": null
},
{
"start": "past",
"end": null,
"display_name": null
},
{
"start": "past",
"end": null,
"display_name": null
},
{
"start": "future",
"end": "past",
"display_name": "International Project Management"
},
{
"start": "future",
"end": "past",
"display_name": "Cybersecurity Fundamentals"
},
{
"start": "future",
"end": "past",
"display_name": ""
},
{
"start": "future",
"end": "past",
"display_name": null
},
{
"start": "future",
"end": "past",
"display_name": null
},
{
"start": "future",
"end": "future",
"display_name": "International Project Management"
},
{
"start": "future",
"end": "future",
"display_name": "Cybersecurity Fundamentals"
},
{
"start": "future",
"end": "future",
"display_name": ""
},
{
"start": "future",
"end": "future",
"display_name": null
},
{
"start": "future",
"end": "future",
"display_name": null
},
{
"start": "future",
"end": null,
"display_name": "International Project Management"
},
{
"start": "future",
"end": null,
"display_name": "Cybersecurity Fundamentals"
},
{
"start": "future",
"end": null,
"display_name": ""
},
{
"start": "future",
"end": null,
"display_name": null
},
{
"start": "future",
"end": null,
"display_name": null
},
{
"start": "future",
"end": null,
"display_name": null
},
{
"start": null,
"end": "past",
"display_name": "International Project Management"
},
{
"start": null,
"end": "past",
"display_name": "Cybersecurity Fundamentals"
},
{
"start": null,
"end": "past",
"display_name": ""
},
{
"start": null,
"end": "past",
"display_name": null
},
{
"start": null,
"end": "past",
"display_name": null
},
{
"start": null,
"end": "future",
"display_name": "International Project Management"
},
{
"start": null,
"end": "future",
"display_name": "Cybersecurity Fundamentals"
},
{
"start": null,
"end": "future",
"display_name": ""
},
{
"start": null,
"end": "future",
"display_name": null
},
{
"start": null,
"end": "future",
"display_name": null
},
{
"start": null,
"end": null,
"display_name": "International Project Management"
},
{
"start": null,
"end": null,
"display_name": "Cybersecurity Fundamentals"
},
{
"start": null,
"end": null,
"display_name": ""
},
{
"start": null,
"end": null,
"display_name": null
},
{
"start": null,
"end": null,
"display_name": null
},
{
"start": null,
"end": null,
"display_name": null
}
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment