diff --git a/sosci2word/_SoSci2Word.mm b/sosci2word/_SoSci2Word.mm index f2af923..dfe1b80 100644 --- a/sosci2word/_SoSci2Word.mm +++ b/sosci2word/_SoSci2Word.mm @@ -388,7 +388,7 @@ - + @@ -412,7 +412,7 @@ - + @@ -468,6 +468,40 @@ + + + + + + + + + + + + + + + + + + + + + + + +

+ um eine neue Instanz zu erzeugen, +

+

+ ruft man die "Konstruktor-Funktion auf" +

+ + +
+
+
diff --git a/sosci2word/sosci2word.py b/sosci2word/sosci2word.py index 1d37ad4..08b0cad 100644 --- a/sosci2word/sosci2word.py +++ b/sosci2word/sosci2word.py @@ -6,6 +6,7 @@ # This code is free software and can be used under the terms of the MIT License. # +import sys from xml.etree import ElementTree @@ -18,6 +19,54 @@ WORD_OUTPUT='Thesis-Fragebogen-import.docx' def convertSosci2Word(): + # Schritt-1 : alle Frage-Definitionen aufsammeln + collectQuestionDefinitions() + # Schritt-2 : die Fragen in der Reihenfolge vom Questionaire + ## TODO + # Schritt-3 : Questionaire in das Word-Dokument ausgeben + ## TODO + + + +class QuestionElement: + def __init__(self, questionID): + self.qid = questionID + + def dump(self): + return "##--Basis--##" + + + +class LikertItem(QuestionElement): + def __init__(self, questionID, question): + QuestionElement.__init__(self, questionID) + + def dump(self): + return "##--LikertItem--##" + + + +class SelectItem(QuestionElement): + def __init__(self, questionID, question): + QuestionElement.__init__(self, questionID) + + def dump(self): + return "##--SelectItem--##" + + + +class TextElement(QuestionElement): + def __init__(self, questionID, question): + QuestionElement.__init__(self, questionID) + + def dump(self): + return "##--TextElement--##" + + + + + +def collectQuestionDefinitions(): # root = ElementTree.parse(SOSCI_XML).getroot() @@ -29,17 +78,26 @@ def convertSosci2Word(): for question in section.findall('question'): title = question.find('title').text desc = question.find('description').text - qustionType = question.find('class').text + questionType = question.find('class').text id_suffix = getSpecificID(question) id_suffix = int(id_suffix) questionID = "%s%02d" % (id_prefix, id_suffix) - print("Question: ID=%s desc=%s type=%s title=%s " % (questionID, desc, qustionType, title)) + print("Question: ID=%s desc=%s type=%s title=%s " % (questionID, desc, questionType, title)) + if questionType == 'scale': + element = LikertItem(questionID, question) + elif questionType == 'select' or questionType == 'dropdown': + element = SelectItem(questionID, question) + elif questionType == 'TextContent': + element = TextElement(questionID, question) + elif questionType == 'checkbox': + pass # ignorieren wir + else: + __err("unbekannter QuestionType:"+questionType) + + print(element.dump()) - - - -# Hilsmittel für SoSci-XML: extrahiert ein ID-Element, das eingeschachtelt in liegt +# Hilfsmittel für SoSci-XML: extrahiert ein ID-Element, das eingeschachtelt in liegt def getSpecificID(element): attribspecific = element.find('attributes.specific') return next(attr.text for attr in attribspecific.findall('attr') if attr.get('id') == 'id') @@ -47,7 +105,13 @@ def getSpecificID(element): +# ---- Hilfsfunktionen +def __err(text): + print('---FAILURE----------------------') + print(text) + print('abort.') + sys.exit(255)