Commit fe906f42 by Shirley He

convert date to obj

parent 2fd27d7a
...@@ -9,6 +9,8 @@ from itertools import product ...@@ -9,6 +9,8 @@ from itertools import product
from itertools import permutations from itertools import permutations
import sys import sys
import json import json
import datetime
import pytz
def parse_field_arguments(): def parse_field_arguments():
...@@ -62,25 +64,35 @@ def parse_field_arguments(): ...@@ -62,25 +64,35 @@ def parse_field_arguments():
# json.dump(fields, outfile) # json.dump(fields, outfile)
def generate_permutations(fields, index, results, current): def generate_permutations(fields, index, results, current):
allKeys = fields.keys() all_permutations_keys = fields.keys()
optionKey = allKeys[index] permutation_option = all_permutations_keys[index]
values = fields[optionKey] values = fields[permutation_option]
# print values
for i in range(len(values)): for i in range(len(values)):
current[optionKey] = values[i] # add other required default fields to dict
current["organization"] = "RITX"
if index+1 < len(allKeys): # generate different organization number for each course
organization_number = "PM9003"+str(i)+"x"
current["number"] = organization_number
current["run"] = "3T2017"
current["user"] = "edx@example.com"
# add permutation fields to dict
current[permutation_option] = values[i]
now = datetime.datetime.now(pytz.UTC)
if values[i] == "future":
future = str(now + datetime.timedelta(days=365))
current[permutation_option] = future
if values[i] == "past":
past = str(now - datetime.timedelta(days=60))
current[permutation_option] = past
if index+1 < len(all_permutations_keys):
generate_permutations(fields, index+1, results, current) generate_permutations(fields, index+1, results, current)
print current
results.append(current.copy())
# print results
results.append(current.copy())
# print current
with open("test_courses.json", "w") as outfile: with open("test_courses.json", "w") as outfile:
json.dump(results, outfile) json.dump(results, outfile)
......
{ {
"permutation_data": { "permutation_data": {
"display_name": [
"International Project Management",
"Cybersecurity Fundamentals",
"",
null
],
"start": [ "start": [
"past", "past",
"future", "future",
...@@ -24,12 +30,7 @@ ...@@ -24,12 +30,7 @@
[], [],
null null
], ],
"display_name": [
"International Project Management",
"Cybersecurity Fundamentals",
"",
null
],
"mobile_available": [ "mobile_available": [
true, true,
false, false,
......
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