forked from ScoDoc/ScoDoc
59 lines
1.6 KiB
Python
Executable File
59 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Outils pour environnements de démo.
|
|
|
|
Change aléatoirement les identites (nom, prenom) d'un ensemble d'étudiants.
|
|
"""
|
|
|
|
import sys
|
|
import random
|
|
import psycopg2
|
|
|
|
DBCNXSTRING='dbname=SCODEMO'
|
|
|
|
# Noms et prénoms les plus fréquents en France:
|
|
NOMS = [ x.strip() for x in open('noms.txt').readlines() ]
|
|
PRENOMS_H = [ x.strip() for x in open('prenoms-h.txt').readlines() ]
|
|
PRENOMS_F = [ x.strip() for x in open('prenoms-f.txt').readlines() ]
|
|
|
|
def nomprenom(sexe):
|
|
"""un nom et un prenom au hasard"""
|
|
if 'e' in sexe.lower():
|
|
prenom = random.choice(PRENOMS_F)
|
|
else:
|
|
prenom = random.choice(PRENOMS_H)
|
|
return random.choice(NOMS), prenom
|
|
|
|
def usage():
|
|
print(f'Usage: {sys.argv[0]} formsemestre_id')
|
|
sys.exit(1)
|
|
|
|
if len(sys.argv) != 2:
|
|
usage()
|
|
formsemestre_id = sys.argv[1]
|
|
|
|
# Liste des etudiants inscrits à ce semestre
|
|
cnx = psycopg2.connect( DBCNXSTRING )
|
|
cursor = cnx.cursor()
|
|
cursor.execute( """select i.etudid
|
|
from identite i, notes_formsemestre_inscription ins
|
|
where i.etudid=ins.etudid and ins.formsemestre_id=%(formsemestre_id)s
|
|
""",
|
|
{ 'formsemestre_id' : formsemestre_id})
|
|
|
|
wcursor = cnx.cursor()
|
|
for (etudid,) in cursor:
|
|
sexe = random.choice( ('M.', 'MME') )
|
|
nom, prenom = nomprenom(sexe)
|
|
print(f'{etudid}: {nom}\t{prenom}')
|
|
args = { 'nom' : nom, 'prenom' : prenom, 'sexe' : sexe, 'etudid' : etudid }
|
|
req = "update identite set nom=%(nom)s, prenom=%(prenom)s, sexe=%(sexe)s where etudid=%(etudid)s"
|
|
#print( req % args)
|
|
wcursor.execute( req, args )
|
|
|
|
|
|
cnx.commit()
|
|
cnx.close()
|
|
|