Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bertille Pesquidoux
TX-collecte-CHATONS
Commits
0b81120b
Commit
0b81120b
authored
May 27, 2020
by
Adrien Laporte
Browse files
Converter fonctionnel
parent
58053520
Changes
3
Hide whitespace changes
Inline
Side-by-side
conversion/ToDo.md
0 → 100644
View file @
0b81120b
# Todo
-
[ ] Mettre la sortie en ligne
-
[ ] Supporter tous les formats
-
[ ] N'exporter que les Chatons valides pour entraide.chatons.org
-
[ ] S'occuper du champ
`edit_link`
conversion/convert.py
View file @
0b81120b
...
...
@@ -12,15 +12,22 @@ args = parser.parse_args()
# Ouverture des fichiers IO
json_input_file
=
args
.
input
.
name
json_output_file
=
(
args
.
output
args
.
output
.
name
if
args
.
output
is
not
None
else
os
.
path
.
splitext
(
json_input_file
)[
0
]
+
".json"
else
os
.
path
.
splitext
(
json_input_file
)[
0
]
+
"
_converted
.json"
)
output_file
=
open
(
json_output_file
,
"w"
,
encoding
=
"utf8"
)
with
open
(
json_input_file
,
"r"
,
encoding
=
"utf8"
)
as
input_file
:
input
=
json
.
loads
(
input_file
.
read
())
converted_chaton
=
convert_json
.
convertValue
(
input
,
"chaton"
)
chatons
=
convert_json
.
convertChaton
(
converted_chaton
)
for
c
in
chatons
:
print
(
f
"Chaton :
{
c
}
\n
"
)
converted_chaton
=
convert_json
.
convertValue
(
input
,
"chaton"
)
liste_chatons
=
convert_json
.
convertChatons
(
converted_chaton
)
json
.
dump
(
[
chaton
for
chaton
in
liste_chatons
],
output_file
,
indent
=
2
,
ensure_ascii
=
False
,
)
output_file
.
close
()
conversion/convert_json.py
View file @
0b81120b
...
...
@@ -97,6 +97,7 @@ def convertStr(v: str, context: str = None) -> str:
soft
=
conversion
[
"values"
][
"software"
].
get
(
v
,
None
)
if
soft
is
None
:
print
(
f
"Software '
{
v
}
' non-existant"
)
# soft = v # On met la valeur maison, au cas où
return
soft
return
None
...
...
@@ -124,7 +125,18 @@ def convertValue(val, context: str = None):
return
None
def
convertChaton
(
c
:
dict
)
->
list
:
def
convertChatonL
(
l
:
list
)
->
list
:
return
[
chaton
for
converted_cs
in
[
# Une liste par Chaton en théorie
convertChatons
(
chaton
)
for
chaton
in
l
]
for
chaton
in
converted_cs
# Une seule liste à la fin
]
def
convertChatonD
(
c
:
dict
)
->
list
:
services
=
c
[
'services'
]
chaton
=
c
.
copy
()
del
chaton
[
'services'
]
...
...
@@ -134,11 +146,25 @@ def convertChaton(c: dict) -> list:
]
def
convertChatons
(
d
)
->
list
:
if
type
(
d
)
is
dict
:
return
convertChatonD
(
d
)
elif
type
(
d
)
is
list
:
return
convertChatonL
(
d
)
else
:
return
[]
def
makeChatonService
(
c
:
dict
,
service
:
dict
)
->
dict
:
nc
=
c
.
copy
()
software
=
service
.
get
(
'software'
)
description
=
conversion
[
'descriptions'
][
'software'
].
get
(
s
ervice
.
get
(
'software'
),
"Aucune description pour ce service"
s
oftware
)
if
description
is
None
:
if
software
is
not
None
:
print
(
f
"Aucune description pour
{
software
}
"
)
description
=
"Aucune description pour ce service"
nc
[
'type'
]
=
description
for
(
k
,
v
)
in
service
.
items
():
nc
[
k
]
=
v
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment