2013-09-06 14:22:16 +00:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IO::File;
|
|
|
|
use XML::Writer;
|
|
|
|
|
|
|
|
my %time_zones = ();
|
|
|
|
my %countries = ();
|
|
|
|
|
2013-09-09 12:11:17 +00:00
|
|
|
open(TIMEZONES, 'timeZones.txt') or die("Cannot open timeZones.txt: $!\n");
|
2013-09-06 14:22:16 +00:00
|
|
|
while (<TIMEZONES>) {
|
|
|
|
my ($country_code, $timezone_id, $gmt_offset_january, $gmt_offset_july, $gmt_offset_raw) = split(/\t/, $_);
|
2013-09-09 20:56:09 +00:00
|
|
|
next if ($country_code !~ /^[A-Z]{2}$/);
|
2013-09-06 14:22:16 +00:00
|
|
|
|
2013-09-09 20:56:09 +00:00
|
|
|
$time_zones{$timezone_id} = {offset => $gmt_offset_january, dst_offset => $gmt_offset_july};
|
2013-09-06 14:22:16 +00:00
|
|
|
}
|
|
|
|
close(TIMEZONES);
|
|
|
|
|
2013-09-09 20:51:36 +00:00
|
|
|
open(COUNTRIES, 'countryInfo.txt') or die("Cannot open countryInfo.txt: $!\n");
|
2013-09-06 14:22:16 +00:00
|
|
|
while (<COUNTRIES>) {
|
|
|
|
my ($country_code, $iso3, $iso_numeric, $fips, $name, $capital, $area, $population, $continent, $tld, $currency_code, $currency_name, $phone, $postal_code_format, $postal_code_regex, $languages, $geonameid, $neighbours, $equivalent_fips_code) = split(/\t/, $_);
|
2013-09-09 20:56:09 +00:00
|
|
|
next if ($country_code !~ /^[A-Z]{2}$/);
|
2013-09-06 14:22:16 +00:00
|
|
|
|
|
|
|
if ($country_code =~ /^[A-Z]{2}$/) {
|
|
|
|
$countries{$country_code} = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(COUNTRIES);
|
|
|
|
|
2013-09-09 20:56:09 +00:00
|
|
|
open(GEONAMES, "cities.txt") or die("Cannot open cities.txt: $!\n");
|
2013-09-09 20:51:36 +00:00
|
|
|
|
2013-09-06 14:22:16 +00:00
|
|
|
my $xml_file = IO::File->new('>geodata.xml');
|
|
|
|
my $writer = XML::Writer->new(OUTPUT => $xml_file, NEWLINES => 0);
|
|
|
|
|
|
|
|
$writer->xmlDecl('utf-8');
|
|
|
|
$writer->startTag('geodata');
|
|
|
|
|
|
|
|
while (<GEONAMES>) {
|
2013-09-09 20:56:09 +00:00
|
|
|
chomp($_);
|
|
|
|
my ($country_code, $name, $latitude, $longitude, $elevation, $timezone) = split(/\t/, $_);
|
|
|
|
|
|
|
|
if (!exists($countries{$country_code})) {
|
|
|
|
print "Unknown country code: $country_code\n";
|
|
|
|
next;
|
2013-09-06 14:22:16 +00:00
|
|
|
}
|
2013-09-09 20:56:09 +00:00
|
|
|
|
|
|
|
if (!exists($time_zones{$timezone})) {
|
|
|
|
print "Unknown time zone: $timezone\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$writer->emptyTag('p',
|
|
|
|
'n' => $name,
|
|
|
|
'lat' => $latitude,
|
|
|
|
'lon' => $longitude,
|
|
|
|
'alt' => $elevation,
|
|
|
|
'c' => $country_code,
|
|
|
|
'tzo' => $time_zones{$timezone}->{offset},
|
|
|
|
'tzd' => $time_zones{$timezone}->{dst_offset}
|
|
|
|
);
|
|
|
|
|
|
|
|
print $., "\n" if ($. % 19083 == 0);
|
2013-09-06 14:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$writer->endTag('geodata');
|
2013-09-09 20:56:09 +00:00
|
|
|
$writer->end();
|
|
|
|
$xml_file->close();
|
|
|
|
|
|
|
|
close GEONAMES;
|
2013-09-06 14:22:16 +00:00
|
|
|
|