Arborescence des pages

On récupère les photos via l'API REST esup-sgc en récupérant les login / uid / eppn depuis des requêtes LDAP.

Remarquez au passage un bug actuellement dans esup-sgc : les photos sont notées comme étant des JPEG alors qu'un grand nombre d'entre elles sont en fait sous format PNG (triste)

Le script python3

#!/usr/bin/python

from ldap3 import Server, Connection, MODIFY_DELETE, MODIFY_ADD
import os
import wget
import imghdr

server = Server('ldap://ldap')
con = Connection(server, user='cn=tata,dc=univ-ville,dc=fr', password='toto')
con.bind()


for etape in ['MES321', 'MES331', 'MES641', 'MES651', 'MES661']:
    con.search('ou=people,dc=univ-ville,dc=fr', '(supannEtuEtape={UAI:0123456A}%s-*)' % etape, attributes=['uid'])
    res = con.response
    dir = '/tmp/%s/' % etape
    os.mkdir(dir)
    nbOk = 0
    nbKo = 0
    for r in res :
        login = r['attributes']['uid'][0]
        try:
            path = dir + login + '.jpg'
            wget.download(url='https://esup-sgc.univ-ville.fr/wsrest/photo/%s@univ-ville.fr/photo?cardEtat=ENABLED&cardEtat=ENCODED' % login, out=path)
            os.rename(path, dir + login + '.' + imghdr.what(path))
            nbOk += 1
        except:
            nbKo += 1
    print('%s : %s ok / %s ko\n' % (etape, nbOk, nbKo))

con.unbind()


Bash pour conversion de png en jpg

find MES* -name "*png" -exec mogrify -format jpg {} \;
find MES* -name "*png" -delete
  • Aucune étiquette