diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-08-02 11:11:01 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-08-02 11:11:01 -0700 |
commit | 45cb24500f1680152bca4ede40b7edaf2f9453f8 (patch) | |
tree | 96146f7fffa1b980a7fe750b87925c3223ab1c95 | |
parent | 44055881b14b322139b6c9c82d718a807f7928ea (diff) |
improve file2json
-rw-r--r-- | tools/file2json.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tools/file2json.py b/tools/file2json.py index 3ee7da10..19f32e17 100644 --- a/tools/file2json.py +++ b/tools/file2json.py @@ -13,8 +13,15 @@ VARNAME - the variable to store it in (the output will be VARNAME = [...]) import os, sys data = open(sys.argv[1], 'r').read() -sdata = map(lambda x: str(ord(x)), data) -json = '[' + ','.join(sdata) + ']' +sdata = map(lambda x: str(ord(x)) + ',', data) +sdata[-1] = sdata[-1].replace(',', '') +lined = [] +while len(sdata) > 0: + lined += sdata[:30] + sdata = sdata[30:] + if len(sdata) > 0: + lined += ['\n'] +json = '[' + ''.join(lined) + ']' print 'var ' + sys.argv[2] + '=' + json + ';' |