We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit de8aded5 authored by tobyink's avatar tobyink

Country codes

parent a87b438f
......@@ -51,6 +51,12 @@ if (isset($_POST['install'])) {
longitude FLOAT,
country CHAR(2))");
$mdb2->query("CREATE TABLE Countries (
country varchar(2) PRIMARY KEY,
country_name varchar(200),
wikipedia_en varchar(120));")
$mdb2->query("CREATE TABLE Users (
username VARCHAR(64) PRIMARY KEY,
password VARCHAR(32) NOT NULL,
......
#!/usr/bin/perl
use CGI qw(escape);
use Encode qw(_utf8_on);
use LWP::Simple;
use strict;
my $data = get('http://en.wikipedia.org/w/index.php?title=ISO_3166-1_alpha-2&action=raw');
_utf8_on($data); # mess with Perl's internals... data is in UTF8, but we need to tell Perl that!
my @lines = split /\r?\n/, $data;
my $longest_name = 0;
my $longest_link = 0;
print "DROP TABLE Countries;\n";
print "CREATE TABLE Countries (country varchar(2) PRIMARY KEY, country_name varchar(200), wikipedia_en varchar(120));\n";
foreach (@lines)
{
# toothpicks stood on end
if (/^ \s* \| \s* # Initial pipe symbol
id=\"([A-Z]{2})\" # ID attribute
\s* \| \s* # Another pipe symbol
<tt>..<\/tt> # Teletype font
\s* \|\| \s* # Double pipe symbol
\[\[ # Double opening brackets
([^\]\|]+) # Link
(\|([^\]]+))? # Link text (optional)
\]\] # Double closing bracket
/xi)
{
my $code = $1;
my $link = escape($2);
my $name = $4 || $2;
$link =~ s/\%20/_/g;
$name =~ s/\'/\'\'/g;
$longest_link = length($link) if length($link) > $longest_link;
$longest_name = length($name) if length($name) > $longest_name;
print "INSERT INTO Countries VALUES ('$code', '$name', 'http://en.wikipedia.org/wiki/$link');\n";
}
}
$longest_link += length('http://en.wikipedia.org/wiki/');
print "-- Longest name: $longest_name\n";
print "-- Longest link: $longest_link\n";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment