mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update ISO 3166 database
This commit is contained in:
parent
1b93d540b7
commit
77af13c5f3
1710
setup/iso3166.xml
1710
setup/iso3166.xml
File diff suppressed because it is too large
Load Diff
1677
setup/iso_3166-1.json
Normal file
1677
setup/iso_3166-1.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -791,7 +791,7 @@ class ISO3166(ISO639): # {{{
|
||||
'iso3166.calibre_msgpack')
|
||||
|
||||
def run(self, opts):
|
||||
src = self.j(self.d(self.SRC), 'setup', 'iso3166.xml')
|
||||
src = self.j(self.d(self.SRC), 'setup', 'iso_3166-1.json')
|
||||
if not os.path.exists(src):
|
||||
raise Exception(src + ' does not exist')
|
||||
dest = self.DEST
|
||||
@ -802,21 +802,21 @@ class ISO3166(ISO639): # {{{
|
||||
self.info('Packed code is up to date')
|
||||
return
|
||||
self.info('Packing ISO-3166 codes to', dest)
|
||||
from lxml import etree
|
||||
root = etree.fromstring(open(src, 'rb').read())
|
||||
with open(src, 'rb') as f:
|
||||
db = json.load(f)
|
||||
codes = set()
|
||||
three_map = {}
|
||||
name_map = {}
|
||||
unicode_type = type(u'')
|
||||
for x in root.xpath('//iso_3166_entry'):
|
||||
two = x.get('alpha_2_code')
|
||||
for x in db['3166-1']:
|
||||
two = x.get('alpha_2')
|
||||
if two:
|
||||
two = unicode_type(two)
|
||||
codes.add(two)
|
||||
name_map[two] = x.get('name')
|
||||
if name_map[two]:
|
||||
name_map[two] = unicode_type(name_map[two])
|
||||
three = x.get('alpha_3_code')
|
||||
three = x.get('alpha_3')
|
||||
if three:
|
||||
three_map[unicode_type(three)] = two
|
||||
x = {u'names':name_map, u'codes':frozenset(codes), u'three_map':three_map}
|
||||
|
Loading…
x
Reference in New Issue
Block a user