Skip to content

Instantly share code, notes, and snippets.

@CodeZombieCH
Created December 4, 2016 20:42
Show Gist options
  • Save CodeZombieCH/037d5dc3e52733558c0ed41172292124 to your computer and use it in GitHub Desktop.
Save CodeZombieCH/037d5dc3e52733558c0ed41172292124 to your computer and use it in GitHub Desktop.
GPSies top 15 countries
<select>
<option value="AF">Afghanistan (27)</option>
<option value="EG">Ägypten (527)</option>
<option value="AL">Albanien (551)</option>
<option value="DZ">Algerien (86)</option>
<option value="AD">Andorra (406)</option>
<option value="AO">Angola (61)</option>
<option value="AI">Anguilla (4)</option>
<option value="AQ">Antarktis (10)</option>
<option value="AG">Antigua und Barbuda (10)</option>
<option value="GQ">Äquatorialguinea (1)</option>
<option value="AR">Argentinien (2088)</option>
<option value="AM">Armenien (609)</option>
<option value="AW">Aruba (72)</option>
<option value="AZ">Aserbaidschan (160)</option>
<option value="ET">Äthiopien (156)</option>
<option value="AU">Australien (7143)</option>
<option value="AX">AX (60)</option>
<option value="BS">Bahamas (9)</option>
<option value="BH">Bahrain (29)</option>
<option value="BD">Bangladesch (51)</option>
<option value="BB">Barbados (31)</option>
<option value="BE">Belgien (90857)</option>
<option value="BZ">Belize (40)</option>
<option value="BJ">Benin (11)</option>
<option value="BM">Bermuda (3)</option>
<option value="BT">Bhutan (18)</option>
<option value="MM">Birma (Myanmar) (143)</option>
<option value="BO">Bolivien (368)</option>
<option value="BA">Bosnien und Herzegowina (598)</option>
<option value="BW">Botsuana (100)</option>
<option value="BV">Bouvet-Insel (1)</option>
<option value="BR">Brasilien (12098)</option>
<option value="BN">Brunei Darussalam (18)</option>
<option value="BG">Bulgarien (4186)</option>
<option value="BF">Burkina Faso (30)</option>
<option value="BI">Burundi (8)</option>
<option value="KY">Cayman-Inseln (8)</option>
<option value="CL">Chile (1500)</option>
<option value="CN">China (6349)</option>
<option value="CK">Cook-Inseln (4)</option>
<option value="CR">Costa Rica (823)</option>
<option value="CW">CW (5)</option>
<option value="DK">Dänemark (47189)</option>
<option value="DE">Deutschland (932322)</option>
<option value="DM">Dominica (24)</option>
<option value="DO">Dominikanische Republik (167)</option>
<option value="DJ">Dschibuti (7)</option>
<option value="EC">Ecuador (414)</option>
<option value="CI">Elfenbeinküste (6)</option>
<option value="SV">El Salvador (51)</option>
<option value="ER">Eritrea (6)</option>
<option value="EE">Estland (1368)</option>
<option value="FK">Falkland-Inseln (9)</option>
<option value="FO">Färöer-Inseln (69)</option>
<option value="FJ">Fidschi (8)</option>
<option value="FI">Finnland (5195)</option>
<option value="FR">Frankreich (146243)</option>
<option value="GF">Französisch Guyana (18)</option>
<option value="PF">Französisch-Polynesien (26)</option>
<option value="GA">Gabun (22)</option>
<option value="GM">Gambia (18)</option>
<option value="GE">Georgien (2873)</option>
<option value="GH">Ghana (50)</option>
<option value="GI">Gibraltar (11)</option>
<option value="GD">Grenada (25)</option>
<option value="GR">Griechenland (7971)</option>
<option value="GL">Grönland (118)</option>
<option value="GB">Großbritannien (67143)</option>
<option value="GP">Guadeloupe (121)</option>
<option value="GU">Guam (1)</option>
<option value="GT">Guatemala (199)</option>
<option value="GG">Guernsey (18)</option>
<option value="GN">Guinea (19)</option>
<option value="GY">Guyana (2)</option>
<option value="HT">Haiti (20)</option>
<option value="HN">Honduras (53)</option>
<option value="HK">Hong Kong (566)</option>
<option value="IN">Indien (3230)</option>
<option value="ID">Indonesien (2102)</option>
<option value="IM">Insel Man (28)</option>
<option value="IQ">Irak (14)</option>
<option value="IR">Iran (Islamische Republik) (586)</option>
<option value="IE">Irland (2821)</option>
<option value="IS">Island (1732)</option>
<option value="IL">Israel (24712)</option>
<option value="IT">Italien (190878)</option>
<option value="JM">Jamaika (29)</option>
<option value="JP">Japan (4559)</option>
<option value="YE">Jemen (19)</option>
<option value="JE">Jersey (22)</option>
<option value="JO">Jordanien (403)</option>
<option value="VG">Jungfern-Inseln (Britisch) (11)</option>
<option value="VI">Jungfern-Inseln (USA) (20)</option>
<option value="KH">Kambodscha (262)</option>
<option value="CM">Kamerun (17)</option>
<option value="CA">Kanada (6204)</option>
<option value="CV">Kap Verde (150)</option>
<option value="KZ">Kasachstan (868)</option>
<option value="QA">Katar (91)</option>
<option value="KE">Kenia (195)</option>
<option value="KG">Kirgistan (1494)</option>
<option value="CO">Kolumbien (724)</option>
<option value="CG">Kongo (Republik Kongo) (2)</option>
<option value="KP">Korea (Demokratische Volksrepublik| Nordkorea) (2)</option>
<option value="KR">Korea (Republik Korea| Südkorea) (3055)</option>
<option value="HR">Kroatien (11768)</option>
<option value="CU">Kuba (854)</option>
<option value="KW">Kuwait (10)</option>
<option value="LA">Laos (418)</option>
<option value="LS">Lesotho (10)</option>
<option value="LV">Lettland (1454)</option>
<option value="LB">Libanon (207)</option>
<option value="LR">Liberia (12)</option>
<option value="LY">Libysch-Arabische Dschamahirija (17)</option>
<option value="LI">Liechtenstein (540)</option>
<option value="LT">Litauen (2707)</option>
<option value="LU">Luxemburg (13785)</option>
<option value="MO">Macau (45)</option>
<option value="MG">Madagaskar (105)</option>
<option value="MW">Malawi (27)</option>
<option value="MY">Malaysien (788)</option>
<option value="MV">Malediven (34)</option>
<option value="ML">Mali (8)</option>
<option value="MT">Malta (203)</option>
<option value="MA">Marokko (1889)</option>
<option value="MH">Marshall-Inseln (1)</option>
<option value="MQ">Martinique (52)</option>
<option value="MR">Mauretanien (32)</option>
<option value="MU">Mauritius (109)</option>
<option value="YT">Mayotte (9)</option>
<option value="MK">Mazedonien (598)</option>
<option value="MX">Mexiko (1347)</option>
<option value="MF">MF (1)</option>
<option value="MD">Moldau (Republik Moldau) (1581)</option>
<option value="MC">Monaco (124)</option>
<option value="MN">Mongolei (255)</option>
<option value="ME">Montenegro (1579)</option>
<option value="MS">Montserrat (3)</option>
<option value="MZ">Mosambik (53)</option>
<option value="NA">Namibia (424)</option>
<option value="NR">Nauru (1)</option>
<option value="NP">Nepal (1119)</option>
<option value="NC">Neukaledonien (123)</option>
<option value="NZ">Neuseeland (3190)</option>
<option value="NL">Niederlande (70600)</option>
<option value="AN">Niederländische Antillen (31)</option>
<option value="NE">Niger (2)</option>
<option value="NG">Nigeria (8)</option>
<option value="NI">Nikaragua (111)</option>
<option value="NO">Norwegen (10228)</option>
<option value="OM">Oman (272)</option>
<option value="AT">Österreich (118650)</option>
<option value="PK">Pakistan (53)</option>
<option value="PS">Palästina (1652)</option>
<option value="PA">Panama (165)</option>
<option value="PG">Papua-Neuguinea (4)</option>
<option value="PY">Paraguay (11)</option>
<option value="PE">Peru (1029)</option>
<option value="PH">Philippinen (590)</option>
<option value="PL">Polen (94922)</option>
<option value="PT">Portugal (86406)</option>
<option value="PR">Puerto Rico (69)</option>
<option value="RE">Reunion (538)</option>
<option value="RW">Ruanda (23)</option>
<option value="RO">Rumänien (8084)</option>
<option value="RU">Russland (129898)</option>
<option value="KN">Saint Kitts und Nevis (12)</option>
<option value="ZM">Sambia (83)</option>
<option value="WS">Samoa (2)</option>
<option value="SM">San Marino (121)</option>
<option value="ST">Sao Tomé und Principe (3)</option>
<option value="SA">Saudi-Arabien (305)</option>
<option value="SE">Schweden (14218)</option>
<option value="CH" selected="selected">Schweiz (63722)</option>
<option value="SN">Senegal (74)</option>
<option value="RS">Serbien (954)</option>
<option value="SC">Seychellen (74)</option>
<option value="SL">Sierra Leone (6)</option>
<option value="ZW">Simbabwe (56)</option>
<option value="SG">Singapur (222)</option>
<option value="SK">Slowakei (Slowakische Republik) (7670)</option>
<option value="SI">Slowenien (7645)</option>
<option value="SB">Solomon-Inseln (2)</option>
<option value="SO">Somalia (14)</option>
<option value="ES">Spanien (109712)</option>
<option value="LK">Sri Lanka (699)</option>
<option value="SS">SS (1)</option>
<option value="LC">St. Lucia (14)</option>
<option value="PM">St. Pierre und Miquelon (1)</option>
<option value="VC">St. Vincent und die Grenadinen (12)</option>
<option value="VA">Staat der Vatikanstadt (138)</option>
<option value="ZA">Südafrika (1945)</option>
<option value="SD">Sudan (33)</option>
<option value="GS">Süd-Georgien und Südliche Sandwich-Inseln (2)</option>
<option value="SR">Suriname (2)</option>
<option value="SJ">Svalbard und Jan-Mayen (7)</option>
<option value="SZ">Swasiland (12)</option>
<option value="SX">SX (2)</option>
<option value="SY">Syrien (132)</option>
<option value="TJ">Tadschikistan (441)</option>
<option value="TW">Taiwan (1406)</option>
<option value="TZ">Tansania (295)</option>
<option value="TH">Thailand (3466)</option>
<option value="TL">Timor-Leste (18)</option>
<option value="TG">Togo (13)</option>
<option value="TT">Trinidad und Tobago (15)</option>
<option value="TD">Tschad (8)</option>
<option value="CZ">Tschechien (26257)</option>
<option value="TN">Tunesien (300)</option>
<option value="TR">Türkei (5192)</option>
<option value="TM">Turkmenistan (47)</option>
<option value="TC">Turks- und Caicos-Inseln (1)</option>
<option value="UG">Uganda (136)</option>
<option value="UA">Ukraine (64503)</option>
<option value="HU">Ungarn (17182)</option>
<option value="UY">Uruguay (123)</option>
<option value="US">USA (41186)</option>
<option value="UZ">Usbekistan (282)</option>
<option value="VU">Vanuatu (1)</option>
<option value="VE">Venezuela (156)</option>
<option value="AE">Vereinigte Arabische Emirate (359)</option>
<option value="VN">Vietnam (1556)</option>
<option value="BY">Weißrussland (13889)</option>
<option value="EH">West-Sahara (7)</option>
<option value="CD">Zaire (37)</option>
<option value="CF">Zentralafrikanische Republik (1)</option>
<option value="CY">Zypern (3207)</option>
</select>
import re
from xml.dom import minidom
class Country:
def __init__(self, name, count):
self.name = name
self.count = count
def __str__(self):
return '{}: {}'.format(self.name, self.count)
xmldoc = minidom.parse('data.xml')
itemlist = xmldoc.getElementsByTagName('option')
print(len(itemlist))
pattern = re.compile('(.*)\s\((\d+)\)')
records = []
for item in itemlist:
value = item.firstChild.nodeValue
match = pattern.search(value)
records.append(Country(match.group(1), int(match.group(2))))
print(records[0].count)
records.sort(key=lambda r: r.count, reverse=True)
for record in records[:15]:
# sysout
#print(record)
# Latex
print('\\hline {} & \\num{{{}}} \\\\'.format(record.name, record.count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment