Skip to content

Commit

Permalink
rewrite some names into common names, to match data-countries
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Oct 18, 2015
1 parent 1d4c8d5 commit 0bd5199
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
8 changes: 4 additions & 4 deletions data/calling_codes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ code,country
77,Kazakhstan
254,Kenya
686,Kiribati
850,"Korea, North"
82,"Korea, South"
850,"North Korea"
82,"South Korea"
965,Kuwait
996,Kyrgyzstan
856,Laos
Expand Down Expand Up @@ -270,8 +270,8 @@ code,country
998,Uzbekistan
678,Vanuatu
58,Venezuela
3906698,"Vatican City State (Holy See)"
379,"Vatican City State (Holy See)"
3906698,"Vatican City"
379,"Vatican City"
84,Vietnam
1808,"Wake Island, USA"
681,"Wallis and Futuna"
Expand Down
8 changes: 4 additions & 4 deletions data/calling_codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,11 @@
"code": "686"
},
{
"country": "Korea, North",
"country": "North Korea",
"code": "850"
},
{
"country": "Korea, South",
"country": "South Korea",
"code": "82"
},
{
Expand Down Expand Up @@ -1084,11 +1084,11 @@
"code": "58"
},
{
"country": "Vatican City State (Holy See)",
"country": "Vatican City",
"code": "3906698"
},
{
"country": "Vatican City State (Holy See)",
"country": "Vatican City",
"code": "379"
},
{
Expand Down
32 changes: 25 additions & 7 deletions tools/update_calling_codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ function write_json($fileName, $list)
}


function extractLinks($s)
{
preg_match_all('/\[\[[\w\d\s,+|]+\]\]/', $s, $matches);

return $matches[0];
}

function mapCountry($c)
{
if ($c == 'Korea, South') {
return 'South Korea';
}

if ($c == 'Korea, North') {
return 'North Korea';
}

if ($c == 'Vatican City State (Holy See)') {
return 'Vatican City';
}

return $c;
}

$res = (new MartinLindhe\MediawikiClient\Client)
->server('en.wikipedia.org')
->cacheTtlSeconds(3600) // 1 hour
Expand Down Expand Up @@ -83,13 +107,6 @@ function write_json($fileName, $list)

$data = substr($x, $pos, $pos2 - $pos);

function extractLinks($s)
{
preg_match_all('/\[\[[\w\d\s,+|]+\]\]/', $s, $matches);

return $matches[0];
}

$list = [];

$rows = explode("\n", $data);
Expand All @@ -100,6 +117,7 @@ function extractLinks($s)
}

$country = cleanText($rows[$i++]);
$country = mapCountry($country);


$codes = extractLinks($rows[$i++]);
Expand Down

0 comments on commit 0bd5199

Please sign in to comment.