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
6c768121
Commit
6c768121
authored
May 24, 2020
by
Adrien Laporte
Browse files
Begin convert
parent
e946e57f
Changes
1
Hide whitespace changes
Inline
Side-by-side
conversion/convert.py
0 → 100755
View file @
6c768121
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import
argparse
from
textwrap
import
dedent
import
os
import
json
def
makeParser
()
->
argparse
.
ArgumentParser
():
"""Permet de créer le argparse initial"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"input"
,
type
=
argparse
.
FileType
(
"r"
),
help
=
dedent
(
"""Fichier JSON à convertir
"""
),
)
parser
.
add_argument
(
"-o"
,
"--output"
,
type
=
argparse
.
FileType
(
"w"
),
required
=
False
,
help
=
"""Fichier dans lequel exporter les données converties"""
,
)
return
parser
parser
=
makeParser
()
args
=
parser
.
parse_args
()
# Ouverture des fichiers IO
json_input_file
=
args
.
input
.
name
json_output_file
=
(
args
.
output
if
args
.
output
is
not
None
else
os
.
path
.
splitext
(
json_input_file
)[
0
]
+
".json"
)
chaton_keys
=
{
"name"
:
"chaton"
,
"url"
:
"chaton_website"
,
}
service_keys
=
{
# "": "type", # Ajouté après coup
"software"
:
"software"
,
# list → str
"public"
:
"open"
,
"weight"
:
"weight"
,
# Todo
"consent"
:
"consent"
,
# Todo
"degradability"
:
"degradability"
,
"url"
:
"endpoint"
,
"magie_noire"
:
"edit_link"
,
# Kececé ?
}
software_names
=
{
# Générés automatiquement
"cryptpad"
:
"Cryptpad"
,
"darkwire.io"
:
"Darkwire.io"
,
"draw.io"
:
"Draw.io"
,
"easyrtc"
:
"EasyRTC"
,
"ethercalc"
:
"Ethercalc"
,
"etherpad"
:
"Etherpad"
,
"filetolink"
:
"Filetolink"
,
"firefoxsend"
:
"FirefoxSend"
,
"framadate"
:
"Framadate"
,
"libreto"
:
"Libreto"
,
"lstu"
:
"LSTU"
,
"lufi"
:
"Lufi"
,
"lutim"
:
"Lutim"
,
"mycryptochat"
:
"MyCryptoChat"
,
"plik"
:
"Plik"
,
"polr"
:
"Polr"
,
"privatebin"
:
"Privatebin"
,
"rs_short"
:
"rs-short"
,
"scrumblr"
:
"Scrumblr"
,
"strut"
:
"Strut"
,
# ajoutés main :
"mattermost"
:
"Mattermost"
}
software_descriptions
=
{
# Parsés depuis les données du framagit le 24/05/2020
"Lufi"
:
"Partage temporaire de fichiers (alternative à WeTransfer, DropSend)"
,
"Draw.io"
:
"Création de schémas et diagrammes (alternative à Visio)"
,
"Privatebin"
:
"Transfert de messages chiffrés (alternative à PasteBin)"
,
"Etherpad"
:
"Rédaction collaborative (alternative à Google Docs)"
,
"Framadate"
:
"Aide à la prise de rendez-vous (alternative à Doodle)"
,
"Plik"
:
"Partage temporaire de fichiers (alternative à WeTransfer, DropSend)"
,
"EasyRTC"
:
"Visioconférence (alternative à Skype, Hangouts, etc.)"
,
"Cryptpad"
:
"Rédaction collaborative (alternative à Google Docs)"
,
"Filetolink"
:
"Partage temporaire de fichiers (alternative à WeTransfer, DropSend)"
,
"Lutim"
:
"Stockage/partage d'images (alternative à Img.ur)"
,
"FirefoxSend"
:
"Partage temporaire de fichiers (alternative à WeTransfer, DropSend)"
,
"Polr"
:
"Raccourcisseur d'URL (alternative à Bit.ly, tinyurl, etc.)"
,
"LSTU"
:
"Raccourcisseur d'URL (alternative à Bit.ly, tinyurl, etc.)"
,
"Jitsi Meet"
:
"Visioconférence (alternative à Skype, Hangouts, etc.)"
,
"MyCryptoChat"
:
"Chat IRC ou Jabber (alternative à MSN)"
,
"Libreto"
:
"Rédaction collaborative (alternative à Google Docs)"
,
"Darkwire.io"
:
"Chat IRC ou Jabber (alternative à MSN)"
,
"Strut"
:
"Présentation collaborative (alternative à Google Drive)"
,
"Scrumblr"
:
"Tableau blanc collaboratif (alternative à Stoodle)"
,
"Ethercalc"
:
"Tableur collaboratif (alternative à Google Sheets)"
,
"rs-short"
:
"Raccourcisseur d'URL (alternative à Bit.ly, tinyurl, etc.)"
,
# 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
showNode
(
str
):
pass
# print(str)
def
debug
(
str
):
print
(
str
)
def
convertDict
(
d
:
dict
,
context
:
str
=
None
)
->
dict
:
showNode
(
f
"D :
{
d
}
,
{
context
}
"
)
return
{
ck
:
cv
for
(
ck
,
cv
)
in
[
(
convertKey
(
k
,
context
),
convertValue
(
v
,
k
))
for
(
k
,
v
)
in
d
.
items
()
]
if
ck
is
not
None
and
cv
is
not
None
}
def
convertList
(
l
:
list
,
context
:
str
=
None
)
->
list
:
showNode
(
f
"L :
{
l
}
,
{
context
}
"
)
return
[
cv
for
cv
in
[
convertValue
(
item
,
context
)
for
item
in
l
]
if
cv
is
not
None
]
def
convertKey
(
k
:
str
,
context
:
str
=
None
)
->
str
:
showNode
(
f
"K :
{
k
}
,
{
context
}
"
)
if
context
==
"services"
:
return
service_keys
.
get
(
k
,
None
)
return
chaton_keys
.
get
(
k
,
None
)
def
convertStr
(
v
:
str
,
context
:
str
=
None
)
->
str
:
showNode
(
f
"S :
{
v
}
,
{
context
}
"
)
if
context
==
"url"
:
return
v
elif
context
==
"name"
:
return
v
elif
context
==
"type"
:
print
(
"Ouiiiii"
)
return
software_names
.
get
(
v
,
None
)
return
conv_values
.
get
(
v
,
None
)
def
convertValue
(
val
,
context
:
str
=
None
):
showNode
(
f
"V :
{
val
}
,
{
context
}
"
)
if
type
(
val
)
is
str
:
return
convertStr
(
val
,
context
)
elif
type
(
val
)
is
dict
:
return
convertDict
(
val
,
context
)
elif
type
(
val
)
is
list
:
return
convertList
(
val
,
context
)
else
:
return
None
with
open
(
json_input_file
,
"r"
,
encoding
=
"utf8"
)
as
input_file
:
input
=
json
.
loads
(
input_file
.
read
())
print
(
input
)
print
(
convertValue
(
input
))
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