diff --git a/extract_card.py b/extract_card.py new file mode 100644 index 0000000..396a33a --- /dev/null +++ b/extract_card.py @@ -0,0 +1,35 @@ +import json, sys +from typing import Dict + +# Пример простого парсера: ищет ключевые слова в строках + +def parse(text: str) -> Dict: + result = { + "title": None, + "subject": None, + "deadline_hint": None, + "deliverable_type": None, + "grading_hints": None, + } + for line in text.splitlines(): + l=line.lower() + if "title" in l: + result["title"] = line.split(":",1)[-1].strip() + elif "subject" in l: + result["subject"] = line.split(":",1)[-1].strip() + elif "deadline" in l: + result["deadline_hint"] = line.split(":",1)[-1].strip() + elif "deliverable" in l: + result["deliverable_type"] = line.split(":",1)[-1].strip() + elif "grading" in l or "feedback" in l: + result["grading_hints"] = line.split(":",1)[-1].strip() + return result + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python extract_card.py ") + sys.exit(1) + with open(sys.argv[1],"r",encoding="utf-8") as f: + text=f.read() + card=parse(text) + print(json.dumps(card,ensure_ascii=False,indent=2))