# the program is provided in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public # License with the Debian GNU/Linux or Univention distribution in file # /usr/share/common-licenses/AGPL-3; if not, see # <http://www.gnu.org/licenses/>. import sys import json import _util if __name__ == '__main__': # check argument (action) args = sys.argv[1:] if len(args) != 2 or '--help' in args or '-h' in args: print >> sys.stderr, 'usage: create_localized_country_labels.py <languageCode> <outfile.json>' sys.exit(1) print 'generating country label data...' countries = _util.get_country_code_to_geonameid_map(3) country_ids = set(countries.values()) labels = _util.get_localized_names(country_ids, args[0]) final_lables = dict([(icountry, labels.get(igeonameid, '')) for icountry, igeonameid in countries.iteritems()]) with open(args[1], 'w') as outfile: json.dump(final_lables, outfile) print '... done :)'
sys.exit(1) locales = args[1:] print('generating country data...') country_data = {} country_default_lang = _util.get_country_default_language() for icountry, ilang in country_default_lang.items(): country_data.setdefault(icountry, {})['default_lang'] = ilang nameservers = _util.get_country_code_to_nameserver_map() for icountry, iservers in nameservers.items(): country_data.setdefault(icountry, {}).update(iservers) country_code_to_geonameid_map = _util.get_country_code_to_geonameid_map() country_geonameids = list(country_code_to_geonameid_map.values()) for ilocale in locales + ['']: print('loading data for locale %s' % ilocale) country_names = _util.get_localized_names(country_geonameids, ilocale) for icode, iid in country_code_to_geonameid_map.items(): data_set = country_data.get(icode) if not data_set: print(' empty country code: %s' % icode) continue ilabel = country_names.get(iid) if ilabel: data_set.setdefault('label', dict())[ilocale] = ilabel with open(args[0], 'wb') as outfile: json.dump(country_data, outfile, indent=2)