[Unicode]   Unicode Localization Interoperability Technical Committee : Bug Tracking Home | Site Map | Search
 

source: trunk/abbrs/src/cookjson.py @ 18

Revision 18, 2.0 KB checked in by srloomis, 22 months ago (diff)

ticket:2 discard dups

Line 
1# -*- coding: utf-8 -*-
2# by srl
3#
4# Cook the ULI JSON by loading CLDR data
5
6import sys
7reload(sys)
8sys.setdefaultencoding("utf-8")
9
10import json
11import os
12
13dbg = False
14
15locs = []
16
17# doing it wrong.
18files = os.walk('../json')
19for ent in files:
20    (path,dirs,files) = ent
21    if(path.find("/.svn") != -1):
22        continue
23    for file in files:
24        if(file.endswith('.json')):
25            locs.append(file.split('.')[0])
26
27#testing
28#locs = ['de']
29
30# TODO: read this from argv[1]
31CLDR_JSON='/home/srl/src/cldr-aux/json/22.1'
32
33for loc in locs:
34    print 'Locale: %s' % (loc)
35    fni = '../json/%s.json' % (loc)
36    fi  = open(fni, 'rb')
37    data = json.load(fi)
38    fi.close()
39
40    #print(data)
41
42    cldrfn = '%s/main/%s.json' % (CLDR_JSON, loc)
43    cldrf = open(cldrfn, 'rb')
44    cldr = json.load(cldrf)
45    cldrf.close()
46
47    # read ULI data
48    abbrs = set(data['data']['abbrs'])
49
50    # TODO: parameterize, use all calendars. Additional items.
51    lists = [cldr["dates"]["calendars"]["gregorian"]["months"]["format"]["abbreviated"], cldr["dates"]["calendars"]["gregorian"]["days"]["format"]["abbreviated"],cldr["dates"]["calendars"]["gregorian"]["eras"]["eraAbbr"]]
52
53    # list of stuff to add
54    #print lists
55    len0 = len(abbrs)
56    print "len: %d" % len(abbrs)
57
58    for cldrlist in lists:
59        for k in cldrlist.keys():
60            v = cldrlist[k]
61            # print v
62            # TODO: use other abbrs besides '.'.  Find out which items cause break.
63            if v[len(v)-1] == '.':
64                # ends with dot
65                abbrs.add(v)
66
67    len1 = len(abbrs)
68
69    print "new len: %d - added %d" % (len(abbrs), (len1-len0))
70    #abbrs.sort()
71    # copy back
72    data['data']['abbrs'] = list(abbrs)
73    data['data']['abbrs'].sort()
74    if len1 > len0:
75        data['about']['cooked'] = 'Loaded %d abbrs from CLDR' % (len1-len0)
76    else:
77        data['about']['cooked'] = 'No abbrs loaded from CLDR'
78
79    fn = '../json-cooked/%s.json' % (loc)
80    f = open(fn, 'wb')
81    print >>f, json.dumps(data, sort_keys=True, indent=4)
82   
83
Note: See TracBrowser for help on using the repository browser.