Ticket #5446: country_codes.py

File country_codes.py, 9.7 KB (added by lcordier, 17 years ago)

Example program to maintain & sort counties.

Line 
1#!/usr/bin/python
2# coding: utf-8
3
4""" This file needs to be maintained by hand.
5
6 see: http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
7 see: http://www.iso.org/iso/iso3166_en_code_lists.txt
8"""
9
10country_code = {'AD': 'Andorra',
11 'AE': 'United Arab Emirates',
12 'AF': 'Afghanistan',
13 'AG': 'Antigua and Barbuda',
14 'AI': 'Anguilla',
15 'AL': 'Albania',
16 'AM': 'Armenia',
17 'AN': 'Netherlands Antilles',
18 'AO': 'Angola',
19 'AQ': 'Antarctica',
20 'AR': 'Argentina',
21 'AS': 'American Samoa',
22 'AT': 'Austria',
23 'AU': 'Australia',
24 'AW': 'Aruba',
25 'AX': 'Aland Islands', # Åland Islands
26 'AZ': 'Azerbaijan',
27 'BA': 'Bosnia and Herzegovina',
28 'BB': 'Barbados',
29 'BD': 'Bangladesh',
30 'BE': 'Belgium',
31 'BF': 'Burkina Faso',
32 'BG': 'Bulgaria',
33 'BH': 'Bahrain',
34 'BI': 'Burundi',
35 'BJ': 'Benin',
36 'BM': 'Bermuda',
37 'BN': 'Brunei Darussalam',
38 'BO': 'Bolivia',
39 'BR': 'Brazil',
40 'BS': 'Bahamas',
41 'BT': 'Bhutan',
42 'BV': 'Bouvet Island',
43 'BW': 'Botswana',
44 'BY': 'Belarus',
45 'BZ': 'Belize',
46 'CA': 'Canada',
47 'CC': 'Cocos (Keeling) Islands',
48 'CD': 'Congo, the Democratic Republic of the',
49 'CF': 'Central African Republic',
50 'CG': 'Congo',
51 'CH': 'Switzerland',
52 'CI': 'Cote d\'Ivoire', # Côte d'Ivoire
53 'CK': 'Cook Islands',
54 'CL': 'Chile',
55 'CM': 'Cameroon',
56 'CN': 'China',
57 'CO': 'Colombia',
58 'CR': 'Costa Rica',
59 'CU': 'Cuba',
60 'CV': 'Cape Verde',
61 'CX': 'Christmas Island',
62 'CY': 'Cyprus',
63 'CZ': 'Czech Republic',
64 'DE': 'Germany',
65 'DJ': 'Djibouti',
66 'DK': 'Denmark',
67 'DM': 'Dominica',
68 'DO': 'Dominican Republic',
69 'DZ': 'Algeria',
70 'EC': 'Ecuador',
71 'EE': 'Estonia',
72 'EG': 'Egypt',
73 'EH': 'Western Sahara',
74 'ER': 'Eritrea',
75 'ES': 'Spain',
76 'ET': 'Ethiopia',
77 'FI': 'Finland',
78 'FJ': 'Fiji',
79 'FK': 'Falkland Islands (Malvinas)',
80 'FM': 'Micronesia, Federated States of',
81 'FO': 'Faroe Islands',
82 'FR': 'France',
83 'FX': 'France, Metropolitan',
84 'GA': 'Gabon',
85 'GB': 'United Kingdom',
86 'GD': 'Grenada',
87 'GE': 'Georgia',
88 'GF': 'French Guiana',
89 'GG': 'Guernsey',
90 'GH': 'Ghana',
91 'GI': 'Gibraltar',
92 'GL': 'Greenland',
93 'GM': 'Gambia',
94 'GN': 'Guinea',
95 'GP': 'Guadeloupe',
96 'GQ': 'Equatorial Guinea',
97 'GR': 'Greece',
98 'GS': 'South Georgia and the South Sandwich Islands',
99 'GT': 'Guatemala',
100 'GU': 'Guam',
101 'GW': 'Guinea-Bissau',
102 'GY': 'Guyana',
103 'HK': 'Hong Kong',
104 'HM': 'Heard Island and McDonald Islands',
105 'HN': 'Honduras',
106 'HR': 'Croatia',
107 'HT': 'Haiti',
108 'HU': 'Hungary',
109 'ID': 'Indonesia',
110 'IE': 'Ireland',
111 'IL': 'Israel',
112 'IM': 'Isle of Man',
113 'IN': 'India',
114 'IO': 'British Indian Ocean Territory',
115 'IQ': 'Iraq',
116 'IR': 'Iran, Islamic Republic of',
117 'IS': 'Iceland',
118 'IT': 'Italy',
119 'JE': 'Jersey',
120 'JM': 'Jamaica',
121 'JO': 'Jordan',
122 'JP': 'Japan',
123 'KE': 'Kenya',
124 'KG': 'Kyrgyzstan',
125 'KH': 'Cambodia',
126 'KI': 'Kiribati',
127 'KM': 'Comoros',
128 'KN': 'Saint Kitts and Nevis',
129 'KP': 'Korea, Democratic People\'s Republic of',
130 'KR': 'Korea, Republic of',
131 'KW': 'Kuwait',
132 'KY': 'Cayman Islands',
133 'KZ': 'Kazakhstan',
134 'LA': 'Lao People\'s Democratic Republic',
135 'LB': 'Lebanon',
136 'LC': 'Saint Lucia',
137 'LI': 'Liechtenstein',
138 'LK': 'Sri Lanka',
139 'LR': 'Liberia',
140 'LS': 'Lesotho',
141 'LT': 'Lithuania',
142 'LU': 'Luxembourg',
143 'LV': 'Latvia',
144 'LY': 'Libyan Arab Jamahiriya',
145 'MA': 'Morocco',
146 'MC': 'Monaco',
147 'MD': 'Moldova, Republic of',
148 'ME': 'Montenegro',
149 'MG': 'Madagascar',
150 'MH': 'Marshall Islands',
151 'MK': 'Macedonia, the former Yugoslav Republic of',
152 'ML': 'Mali',
153 'MM': 'Myanmar',
154 'MN': 'Mongolia',
155 'MO': 'Macao',
156 'MP': 'Northern Mariana Islands',
157 'MQ': 'Martinique',
158 'MR': 'Mauritania',
159 'MS': 'Montserrat',
160 'MT': 'Malta',
161 'MU': 'Mauritius',
162 'MV': 'Maldives',
163 'MW': 'Malawi',
164 'MX': 'Mexico',
165 'MY': 'Malaysia',
166 'MZ': 'Mozambique',
167 'NA': 'Namibia',
168 'NC': 'New Caledonia',
169 'NE': 'Niger',
170 'NF': 'Norfolk Island',
171 'NG': 'Nigeria',
172 'NI': 'Nicaragua',
173 'NL': 'Netherlands',
174 'NO': 'Norway',
175 'NP': 'Nepal',
176 'NR': 'Nauru',
177 'NU': 'Niue',
178 'NZ': 'New Zealand',
179 'OM': 'Oman',
180 'PA': 'Panama',
181 'PE': 'Peru',
182 'PF': 'French Polynesia',
183 'PG': 'Papua New Guinea',
184 'PH': 'Philippines',
185 'PK': 'Pakistan',
186 'PL': 'Poland',
187 'PM': 'Saint Pierre and Miquelon',
188 'PN': 'Pitcairn',
189 'PR': 'Puerto Rico',
190 'PS': 'Palestinian Territory, Occupied',
191 'PT': 'Portugal',
192 'PW': 'Palau',
193 'PY': 'Paraguay',
194 'QA': 'Qatar',
195 'RE': 'Reunion', # Réunion
196 'RO': 'Romania',
197 'RS': 'Serbia',
198 'RU': 'Russian Federation',
199 'RW': 'Rwanda',
200 'SA': 'Saudi Arabia',
201 'SB': 'Solomon Islands',
202 'SC': 'Seychelles',
203 'SD': 'Sudan',
204 'SE': 'Sweden',
205 'SG': 'Singapore',
206 'SH': 'Saint Helena',
207 'SI': 'Slovenia',
208 'SJ': 'Svalbard and Jan Mayen',
209 'SK': 'Slovakia',
210 'SL': 'Sierra Leone',
211 'SM': 'San Marino',
212 'SN': 'Senegal',
213 'SO': 'Somalia',
214 'SR': 'Suriname',
215 'ST': 'Sao Tome and Principe',
216 'SV': 'El Salvador',
217 'SY': 'Syrian Arab Republic',
218 'SZ': 'Swaziland',
219 'TC': 'Turks and Caicos Islands',
220 'TD': 'Chad',
221 'TF': 'French Southern Territories',
222 'TG': 'Togo',
223 'TH': 'Thailand',
224 'TJ': 'Tajikistan',
225 'TK': 'Tokelau',
226 'TL': 'Timor-Leste',
227 'TM': 'Turkmenistan',
228 'TN': 'Tunisia',
229 'TO': 'Tonga',
230 'TR': 'Turkey',
231 'TT': 'Trinidad and Tobago',
232 'TV': 'Tuvalu',
233 'TW': 'Taiwan, Province of China',
234 'TZ': 'Tanzania, United Republic of',
235 'UA': 'Ukraine',
236 'UG': 'Uganda',
237 #'UK': 'United Kingdom',
238 'UM': 'United States Minor Outlying Islands',
239 'US': 'United States',
240 'UY': 'Uruguay',
241 'UZ': 'Uzbekistan',
242 'VA': 'Holy See (Vatican City State)',
243 'VC': 'Saint Vincent and the Grenadines',
244 'VE': 'Venezuela',
245 'VG': 'Virgin Islands, British',
246 'VI': 'Virgin Islands, U.S.',
247 'VN': 'Viet Nam',
248 'VU': 'Vanuatu',
249 'WF': 'Wallis and Futuna',
250 'WS': 'Samoa',
251 'YE': 'Yemen',
252 'YT': 'Mayotte',
253 'YU': 'Yugoslavia',
254 'ZA': 'South Africa',
255 'ZM': 'Zambia',
256 'ZW': 'Zimbabwe'}
257
258country_list = list(country_code.iteritems())
259country_list.sort(key=lambda x: x[1])
260# country_list.insert(1, country_list.pop(-1)) # fix Åland Islands' position
261
262output = open('countries.py', 'w')
263
264output.write('from django.utils.translation import ugettext as _\n\n')
265output.write('COUNTRIES = (\n')
266for cc, name in country_list:
267 output.write(" ('%s', _('%s')),\n" % (cc, name.encode('string-escape')))
268
269output.write(" ('ZZ', _('Unknown or unspecified country')),\n")
270output.write(')\n')
271output.close()
Back to Top