@voljega Oui, avec lxml tu peux sans soucis, c'est même conseillé. Cependant, même les libs internes de python le peuvent (elles sont juste un poil plus lentes (aucune n'est plus rapide que lxml))
Voilà mon script qui génère un fichier "liste.js" :
| |
| |
| import os,glob,collections,json |
| from lxml.etree import pa**e |
| |
| Game = collections.namedtuple('Game', 'console name genre date image path') |
| |
| def listgames(p,opt="*"): |
| |
| def get(i,e): |
| ll=i.xpath(e) |
| return ll[0].text if ll else None |
| |
| ll=[] |
| for f in sorted(glob.glob( os.path.join(p,opt,"gamelist.xml") )): |
| try: |
| for i in pa**e(f).xpath("//game"): |
| fpath=os.path.dirname(f) |
| console=os.path.basename(fpath) |
| |
| name,genre,date,image=get(i,"name"),get(i,"genre"),get(i,"releasedate"),get(i,"image") |
| path = os.path.realpath(os.path.join(fpath,get(i,"path"))) |
| |
| if get(i,"hidden")=="true": continue |
| if genre and genre.strip().lower().startswith("bios"): continue |
| if image: image = os.path.join( fpath, image ) |
| if date: date=date.strip()[:4] |
| |
| ll.append( Game(console,name,genre,date,image,path) ) |
| except Exception as e: |
| print "Fichier XML invalide:",f,e |
| return ll |
| |
| def genJS(ll): |
| ll=[{"name":i.name,"console":i.console,"genre":i.genre or "NO GENRE","year":i.date or "NO YEAR","image":i.image} for i in ll] |
| with open('liste.js', 'w') as fid: |
| fid.write("var liste="); |
| json.dump(ll, fid) |
| |
| if __name__ == "__main__": |
| ll=listgames("/media/recalbox/roms") |
| |
| print( len(ll) ) |
| genJS(ll) |
Ce fichier est chargé par https://in-the.appspot.com/recalbox/index.html ...
(du coup, si vous voulez le faire chez vous, suffit de recupérer cet "index.html" (show source, ou le télécharger, et de mettre le liste.js généré par le script python)
C'est juste un "index.html" de base (y a juste le css minimum, mais on peut trier les colonnes 