X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=parse%2Fparse-wiki-countrylist.pl;fp=parse%2Fparse-wiki-countrylist.pl;h=fc0437b7140d7502eab971f59eb8da877f2426b3;hb=9f7b3c1a46383496e6a30e0aad8d4252e1a94fda;hp=0000000000000000000000000000000000000000;hpb=eb9ee3742ba220deebc83771b03ffdc7f6a4d59c;p=ccbs diff --git a/parse/parse-wiki-countrylist.pl b/parse/parse-wiki-countrylist.pl new file mode 100644 index 0000000..fc0437b --- /dev/null +++ b/parse/parse-wiki-countrylist.pl @@ -0,0 +1,34 @@ +#! /usr/bin/perl +use strict; +use warnings; + +# Parses country list from +# http://en.wikipedia.org/w/index.php?title=List_of_IOC_country_codes&action=edit + +print "begin;\n"; + +while (<>) { + m/ + ^ \* \s* + ( [A-Z]{3} ) # country code + \s* - \s* + \[\[ + ( ?: .*? \| ) ? # optional article lookup + ( .*? ) # country name + \]\] + /x or next; + + my ($countrycode, $countryname) = ($1, $2); + + # fix some wikisyntax ickyness :-) + $countryname =~ s/\]\]//g; + $countryname =~ s/\[\[//g; + + # minimal SQL escaping + $countryname =~ s/'/\\'/g; + + printf "INSERT INTO countries (countryname,countrycode) VALUES ('%s','%s');\n", + $countryname, $countrycode; +} + +printf "commit;\n";