Skip to content

Commit 9025038

Browse files
author
Nenad Stojanovikj
committed
Fix bug with delimiter character and wrong loop statement
1 parent 3fad6b5 commit 9025038

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
build/
33
dist/
44
CSV2QTI.spec
5+
*.sublime-project
6+
*.sublime-workspace

CSV2QTI.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
parser.add_argument('--quotechar', metavar='quotechar', default='"', help='Quote character for the csv file')
1818

1919
args = parser.parse_args()
20-
questions = CSVImporter().getQuestions(args.csv)
20+
questions = CSVImporter(args.delimiter, args.quotechar).getQuestions(args.csv)
2121

2222
if not os.path.exists(args.output):
2323
os.makedirs(args.output)
@@ -30,7 +30,6 @@
3030
questions[i].title_id = questions[i].title.lower()
3131
xmlGenerator.saveXML(questions[i], args.output + '/' + args.output + '/' + questions[i].title + '.xml')
3232
xmlGenerator.generateManifest(args.output, args.prefix + "_pack")
33-
33+
print "%d items generated!" % len(questions)
3434
shutil.make_archive(args.output, 'zip', args.output)
35-
3635
shutil.rmtree(args.output, ignore_errors=True)

CSVImporter.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
class CSVImporter:
55

66
def __init__(self, delimiter = ',', quotechar='"'):
7-
self.delimiter = delimiter
7+
if delimiter == '\\t':
8+
self.delimiter = '\t'
9+
else:
10+
self.delimiter = delimiter
811
self.quotechar = quotechar
912

1013
def getQuestions(self, question_file):
1114
questions = []
1215
with open(question_file, 'rb') as csvfile:
1316
reader = csv.reader(csvfile, delimiter=self.delimiter, quotechar=self.quotechar)
1417
for row in reader:
18+
if (len(row) < 4):
19+
continue
1520
question = Question()
1621
question.question = row[0]
1722
question.correct_answer = row[1]
1823
for i in range(2, len(row)):
1924
question.answers.append(row[i]);
20-
questions.append(question)
21-
return questions
25+
questions.append(question)
26+
return questions

xmlGenerator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def saveXML(question, filename):
77
doc, tag, text = Doc().tagtext();
8-
question.correct_answer = 'A' + question.correct_answer.__str__()
8+
question.correct_answer = 'A' + question.correct_answer
99
doc.asis('<?xml version="1.0" encoding="UTF-8"?>'\
1010
'<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p0"'\
1111
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'\

0 commit comments

Comments
 (0)