Browse Source

script pour migrer les datas d'un salon à un autre

master
nemesis 2 years ago
parent
commit
1c8770f926
  1. 42
      alter_bieres_quotes_citations_welcome_modo_salons.py
  2. 46
      alter_modules.py

42
alter_bieres_quotes_citations_welcome_modo_salons.py

@ -0,0 +1,42 @@
#!/usr/bin/python
# coding: utf8
import pickle
import sys
contenu = {}
new = {}
statut = True
def charger(fic):
global contenu
try:
with open(fic, "rb") as fichier:
loader = pickle.Unpickler(fichier)
contenu = loader.load()
except:
contenu = {}
def sauver(fic):
with open(fic, "wb") as fichier:
saver = pickle.Pickler(fichier)
saver.dump(contenu)
if (len(sys.argv) is 4):
charger(sys.argv[1])
try:
for cle in contenu:
if (cle == sys.argv[2]):
print(cle)
new[sys.argv[3]] = contenu[cle]
else:
new[cle] = contenu[cle]
except Exception as err:
print(err)
statut = False
if (statut):
contenu = new
sauver(sys.argv[1])
else:
print("lecture.py <fichier> <salon_orig> <salon_dest>")

46
alter_modules.py

@ -0,0 +1,46 @@
#!/usr/bin/python
# coding: utf8
import pickle
import sys
contenu = {}
new = {}
statut = True
def charger(fic):
global contenu
try:
with open(fic, "rb") as fichier:
loader = pickle.Unpickler(fichier)
contenu = loader.load()
except:
contenu = {}
def sauver(fic):
with open(fic, "wb") as fichier:
saver = pickle.Pickler(fichier)
saver.dump(contenu)
if (len(sys.argv) is 4):
fic=sys.argv[1]
salon_orig=sys.argv[2]
salon_dst=sys.argv[3]
charger(fic)
try:
for cle,valeur in contenu.items():
if (cle[0] == salon_orig):
mod=cle[1]
print(str(salon_orig) + ":" + str(mod))
new[salon_dst,mod] = valeur
else:
new[cle] = valeur
except Exception as err:
print(err)
statut = False
if (statut):
contenu = new
sauver(fic)
else:
print("lecture.py <fichier> <salon_orig> <salon_dest>")
Loading…
Cancel
Save