Skip to content

Commit

Permalink
Pre autofill generator for 'New' option in forms script
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Jan 18, 2024
1 parent c2ccdfc commit f179227
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions doc/script/autofill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json

form_path = "./../../backend/source/forms/"

forms = [{
"file": "1699353915355.prod.json",
"qid": 1699354220734
}, {
"file": "1699354006503.prod.json",
"qid": 1699354006535
}, {
"file": "1701172125596.prod.json",
"qid": 1701172125598
}, {
"file": "1701757876668.prod.json",
"qid": 1701757914033
}]


def autofill(form):
with open(form_path + form["file"], "r") as file:
data = json.load(file)
options = []
for qg in data["question_groups"]:
for q in qg["questions"]:
if q.get('options'):
options.append({
"id": q["id"],
"answer": [q['options'][0]["name"]]
})
for qg in data["question_groups"]:
for q in qg["questions"]:
if q["id"] == form["qid"]:
q.update({
"pre": {
"answer": ["New"],
"fill": options
}
})
with open(form_path + form["file"], "w") as file:
json.dump(data, file, indent=2)
print("UPDATE", form["file"])


for f in forms:
autofill(f)

0 comments on commit f179227

Please sign in to comment.