Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle to amc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathieu Loiseau
moodle to amc
Commits
6bd39509
Commit
6bd39509
authored
3 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
load document + categories
parent
8c83b735
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
XML_Moodle.py
+49
-0
49 additions, 0 deletions
XML_Moodle.py
utils.py
+11
-0
11 additions, 0 deletions
utils.py
with
60 additions
and
0 deletions
XML_Moodle.py
0 → 100755
+
49
−
0
View file @
6bd39509
#!/usr/bin/env python3
import
xml.etree.ElementTree
as
ET
from
utils
import
strip_tags
,
mlang_2_multiling
class
Quizz
:
def
__init__
(
self
,
file_name
):
self
.
file_name
=
file_name
self
.
tree
=
ET
.
parse
(
self
.
file_name
)
self
.
questions
=
[]
self
.
parse
()
def
get_tree
(
self
):
return
self
.
tree
def
parse
(
self
):
questions
=
self
.
tree
.
findall
(
"
question
"
)
for
q
in
questions
:
if
q
.
attrib
[
"
type
"
]
==
"
category
"
:
c
=
q
.
find
(
"
category/text
"
).
text
.
replace
(
"
$course$/top/
"
,
""
).
replace
(
"
/
"
,
"
:
"
).
replace
(
"
::
"
,
"
/
"
)
else
:
self
.
questions
.
append
(
Question
(
q
,
c
))
def
__str__
(
self
):
res
=
""
for
q
in
self
.
questions
:
res
+=
str
(
q
)
return
res
class
Question
:
def
__init__
(
self
,
xmlQ
,
c
):
self
.
q
=
mlang_2_multiling
(
strip_tags
(
xmlQ
.
find
(
"
questiontext/text
"
).
text
))
self
.
category
=
c
def
__str__
(
self
):
return
"""
\\
element{
"""
+
self
.
category
+
"""
}{
\\
begin{questionmult}{Def}
\\
nbpoints{0,5}
"""
+
self
.
q
+
"""
\\
begin{choices}
\\
correctchoice{L
'
utilisation d
'
un traitement de texte en cours de langue.}
\b
areme{b=0.25}
\\
correctchoice{L
'
évaluation de l
'
interface d
'
un concordancier en vue de son utilisation en classe d
'
anglais.}
\b
areme{b=0.15}
\\
correctchoice{L
'
utilisation d
'
un glossaire en ligne sur l
'
informatique en cours de FLE.}
\b
areme{b=0.15}
\\
wrongchoice{L
'
utilisation d
'
un dictionnaire en cours d
'
anglais.}
\b
areme{b=0,m=-0.25}
\\
wrongchoice{La création d
'
un glossaire en ligne sur l
'
informatique.}
\b
areme{b=0}
\\
end{choices}
\\
explain{La création d
'
un lexique ne relève pas intrinsèquement de l
'
ALAO, encore faut-il que son usage soit lié à l
'
apprentissage d
'
une langue.}
\\
end{questionmult}
}
\n\n
"""
if
__name__
==
"
__main__
"
:
quizz
=
Quizz
(
"
quiz-GI-4-SID-S1-top-20201204-1620.xml
"
)
print
(
quizz
)
This diff is collapsed.
Click to expand it.
utils.py
0 → 100644
+
11
−
0
View file @
6bd39509
#!/usr/bin/env python3
from
re
import
compile
,
sub
def
remove_moodle_cdata
(
txt
):
return
txt
.
replace
(
"
<![CDATA[
"
,
""
).
replace
(
"
]]>
"
,
""
)
def
strip_tags
(
txt
):
return
sub
(
compile
(
'
<.*?>
'
),
''
,
remove_moodle_cdata
(
txt
))
def
mlang_2_multiling
(
txt
):
return
sub
(
r
"
\{mlang en\}(.*?)\{mlang\}\{mlang other\}(.*?)\{mlang\}
"
,
r
"
\\multiling{\2}{\1}
"
,
txt
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment