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
4b0c5a3d
Commit
4b0c5a3d
authored
May 24, 2020
by
Adrien Laporte
Browse files
Add degradability
parent
6c768121
Changes
2
Hide whitespace changes
Inline
Side-by-side
conversion/convert.py
View file @
4b0c5a3d
...
...
@@ -43,11 +43,12 @@ json_output_file = (
chaton_keys
=
{
"name"
:
"chaton"
,
"url"
:
"chaton_website"
,
"services"
:
"services"
,
}
service_keys
=
{
# "": "type", # Ajouté après coup
"software"
:
"software"
,
# list → str
# "": "type", # Ajouté après coup
"public"
:
"open"
,
"weight"
:
"weight"
,
# Todo
"consent"
:
"consent"
,
# Todo
...
...
@@ -108,17 +109,16 @@ software_descriptions = {
# Ajoutés à la main :
}
degradability
=
{
"Jamais"
,
"1 semaine"
,
"6 mois"
,
"12 mois"
}
# ToDo fonction
conv_values
=
{
"http"
:
"HTTP"
,
"tout.e.s"
:
"Tout⋅e⋅s"
,
"cercle_prive"
:
"Cercle privé"
,
}
input
=
{
"urll"
:
"http"
,
"a"
:
[
"out.e.s"
,
"cercle_prive"
,
{
"b"
:
"http"
,},]}
def
convertDegradability
(
nb
:
int
)
->
str
:
if
nb
==
0
:
return
"Jamais"
elif
nb
<
7
:
return
"1 semaine"
elif
nb
<
6
*
30.5
:
return
"6 mois"
else
:
return
"12 mois"
def
showNode
(
str
):
...
...
@@ -164,15 +164,22 @@ def convertStr(v: str, context: str = None) -> str:
return
v
elif
context
==
"name"
:
return
v
elif
context
==
"type"
:
print
(
"Ouiiiii"
)
elif
context
==
"software"
:
return
software_names
.
get
(
v
,
None
)
return
conv_values
.
get
(
v
,
None
)
return
None
def
convertInt
(
v
:
int
,
context
:
str
=
None
)
->
str
:
if
context
==
"degradability"
:
return
convertDegradability
(
v
)
return
None
def
convertValue
(
val
,
context
:
str
=
None
):
showNode
(
f
"V :
{
val
}
,
{
context
}
"
)
if
type
(
val
)
is
int
:
return
convertInt
(
val
,
context
)
if
type
(
val
)
is
str
:
return
convertStr
(
val
,
context
)
elif
type
(
val
)
is
dict
:
...
...
@@ -187,4 +194,5 @@ with open(json_input_file, "r", encoding="utf8") as input_file:
input
=
json
.
loads
(
input_file
.
read
())
print
(
input
)
print
()
print
(
convertValue
(
input
))
conversion/test_chaton.json
0 → 100644
View file @
4b0c5a3d
{
"name"
:
"Picasoft"
,
"url"
:
"https://picasoft.net"
,
"services"
:
[
{
"type"
:
"rss"
,
"software"
:
"mattermost"
,
"degradability"
:
12
}
],
"structure"
:
"association"
,
"status"
:
"approuve"
}
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