From 81f27ef83293f13cc483dc67d4de89c835e5f53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kralj?= Date: Mon, 30 Jan 2023 15:57:08 +0100 Subject: [PATCH] =?UTF-8?q?Dodan=20Python=20skript=20za=20generiranje=20Mo?= =?UTF-8?q?odle=20vpra=C5=A1anj=20(#1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Dodan Python skript za generiranje Moodle vprašanj * Popravljena vprašanja z risanjem --- .gitignore | 3 +++ moodle_gen.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 moodle_gen.py diff --git a/.gitignore b/.gitignore index a8e938c..0d60e6b 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +# moodle_gen.py output +radioamaterstvo.xml \ No newline at end of file diff --git a/moodle_gen.py b/moodle_gen.py new file mode 100644 index 0000000..6ff5a06 --- /dev/null +++ b/moodle_gen.py @@ -0,0 +1,71 @@ +import json +import base64 + +def gen_vprasanje(ime, vprasanje, odgovori, pravilen , slika = None): + k = doloci_kategorijo(ime) + c = f""" + + $course$/top/{k} + + + """ + + if(slika != None and k != "Risanje"): + with open(f"assets/images/{slika}", "rb") as image_file: + vprasanje += f"
" + + ans = "" + if(odgovori != None): + for o in range(len(odgovori)): + p = 0 + if(o == pravilen): + p = 100 + ans += f""" + + + """ + + return f"""{c} + + {ime} + + + + + none + {ans} + + """ + else: + return f"""{c} + + {ime} + + + Za lažje ocenjevanje, v polje vpišite neko besedilo.]]> + + monospaced + 1 + 2 + 0 + """ + +def doloci_kategorijo(stevilka): + global cat + for c in cat: + for q in c["questions"]: + if q[0] <= stevilka and stevilka <= q[1]: + return c["title"] + +f = open("assets/questions.json") +b = json.load(f) + +q = b["questions"] +cat = b["categories"] + +f = open("radioamaterstvo.xml", "w") +f.write("""""") +for qu in q: + f.write(gen_vprasanje(qu["id"], qu["question"], qu["answers"], qu["correct"], qu["image"])) +f.write("""""") +f.close()