converter.py 672 Bytes
Newer Older
Daniel STAN's avatar
Daniel STAN committed
1 2 3
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

4 5
import json
import glob
Daniel STAN's avatar
Daniel STAN committed
6
import os,sys
7 8 9 10 11 12 13 14 15 16 17
# Basic converter to json, avec roles nounous partout

init_path = '/home/dstan/crans/passwords/'
final_path = '/home/dstan/crans/passwords/v2/'

os.chdir(init_path)

filenames = glob.glob('*.asc')

encoder=json.JSONEncoder()
for filename in filenames:
Daniel STAN's avatar
Daniel STAN committed
18 19 20 21 22 23 24
    fname=final_path+filename[:-4]+'.json'
    if os.path.exists(fname):
        print "%s already exists, ignored" % filename
        continue
    else:
        print "Traitement de %s" % filename
    nf = file(fname,'w')
25 26 27 28
    
    nf.write(encoder.encode({'roles':['nounous']\
        ,'contents':open(filename).read()}))