forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -3,7 +3,8 @@
|
||||
|
||||
"""Outils pour environnements de démo.
|
||||
|
||||
Change aléatoirement les identites (nip, civilite, nom, prenom) des étudiants d'un semestre.
|
||||
Change aléatoirement les identites (nip, civilite, nom, prenom) des étudiants.
|
||||
Un semestre ou tous si non spécifié.
|
||||
|
||||
Le NIP est choisi aléatoirement (nombre entier à 8 chiffres).
|
||||
Les noms et prénoms sont issus des fichiers noms.txt, prenoms-h.txt, prenoms-f.txt
|
||||
@ -19,37 +20,39 @@ from gen_nomprenoms import nomprenom
|
||||
|
||||
|
||||
def usage():
|
||||
print(f"Usage: {sys.argv[0]} dbname formsemestre_id")
|
||||
print(f"Usage: {sys.argv[0]} dbname [formsemestre_id]")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
if len(sys.argv) not in (2, 3):
|
||||
usage()
|
||||
|
||||
dbname = sys.argv[1]
|
||||
formsemestre_id = sys.argv[2]
|
||||
formsemestre_id = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
DBCNXSTRING = f"dbname={dbname}"
|
||||
|
||||
# Liste des etudiants inscrits à ce semestre
|
||||
cnx = psycopg2.connect(DBCNXSTRING)
|
||||
cursor = cnx.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"select count(*) from notes_formsemestre where id=%(formsemestre_id)s",
|
||||
{"formsemestre_id": formsemestre_id},
|
||||
)
|
||||
nsem = cursor.fetchone()[0]
|
||||
if nsem != 1:
|
||||
print(f"{nsem} formsemestre matching {formsemestre_id} in {dbname}")
|
||||
sys.exit(2)
|
||||
|
||||
cursor.execute(
|
||||
"""select i.id
|
||||
from identite i, notes_formsemestre_inscription ins
|
||||
where i.id=ins.etudid and ins.formsemestre_id=%(formsemestre_id)s
|
||||
""",
|
||||
{"formsemestre_id": formsemestre_id},
|
||||
)
|
||||
if formsemestre_id is None:
|
||||
cursor.execute("SELECT i.id from identite i")
|
||||
else:
|
||||
cursor.execute(
|
||||
"select count(*) from notes_formsemestre where id=%(formsemestre_id)s",
|
||||
{"formsemestre_id": formsemestre_id},
|
||||
)
|
||||
nsem = cursor.fetchone()[0]
|
||||
if nsem != 1:
|
||||
print(f"{nsem} formsemestre matching {formsemestre_id} in {dbname}")
|
||||
sys.exit(2)
|
||||
cursor.execute(
|
||||
"""select i.id
|
||||
from identite i, notes_formsemestre_inscription ins
|
||||
where i.id=ins.etudid and ins.formsemestre_id=%(formsemestre_id)s
|
||||
""",
|
||||
{"formsemestre_id": formsemestre_id},
|
||||
)
|
||||
|
||||
wcursor = cnx.cursor()
|
||||
n = 0
|
||||
|
Loading…
Reference in New Issue
Block a user