Radreise-Wiki:Route-Management.pl: Unterschied zwischen den Versionen

Aus Radreise-Wiki
 
(13 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 12: Zeile 12:


'''Quellcode des Skripts:'''
'''Quellcode des Skripts:'''
  <nowiki>
  <nowiki>
use strict;
use strict;
 
my $flags;
my $flags;
 
if ($ARGV[0]) {
if ($ARGV[0]) {
 
$flags = $ARGV[0];
$flags = $ARGV[0];
 
} else {
} else {
 
$flags = "0101000";
$flags = "0101000";
}
}
 
my @flags = split //, $flags;
my @flags = split //, $flags;
 
#=========================
#=========================
# Control-Flags
# Control-Flags
 
# 0101000 Update only recently changed Routefiles
# 0101000 Update only recently changed Routefiles - show changed Trackfiles
# 0011000 Update all Routefiles
# 0010100 Update all Trackfiles - do this first and get kml-Files
# 0010100 Update all Trackfiles
# 0011000 Update all Routefiles
# 0010010 Modify all Routefiles
# 0010010 Modify all Routefiles
# 0010011 Modify and upload all Routefiles
# 0010011 Modify and upload all Routefiles
 
my $updateDates    = $flags[0]; # 1 = Read all Route- and KMZ-History Pages and update Listfile Dates
my $updateDates    = $flags[0]; # 1 = Read all Route- and KMZ-History Pages and update  
#    Listfile Dates
my $updateRecent    = $flags[1]; # 1 = Only update Routefiles from Wiki Recent Changes Page
 
                                  # 0 = Update all Routefiles
my $updateRecent    = $flags[1]; # 1 = Only update Routefiles from Wiki Recent Changes Page
                                # 0 = Update all Routefiles
my $updateAllRoutes = $flags[2]; # 1 = Treat all Routefiles
 
                                  # 0 = Only treat touched Routefiles
my $updateAllRoutes = $flags[2]; # 1 = Treat all Routefiles
                                # 0 = Only treat touched Routefiles
my $updateRoutes    = $flags[3]; # 1 = Update Routefiles from Wiki
 
                                  # 0 = Do not update Routefiles
my $updateRoutes    = $flags[3]; # 1 = Update Routefiles from Wiki
                                # 0 = Do not update Routefiles
my $updateAllKMZ    = $flags[4]; # 1 = Update KMZ Files from Wiki and extract the KML content
 
my $updateAllKMZ    = $flags[4]; # 1 = Update KMZ Files from Wiki and extract the KML content
my $modify          = $flags[5]; # 1 = Modify Routefiles
 
my $upload          = $flags[6]; # 1 = Upload modified Routefiles to Wiki
my $modify          = $flags[5]; # 1 = Modify Routefiles
my $upload          = $flags[6]; # 1 = Upload modified Routefiles to Wiki
 
#=====================
 
# Import Date Library
#=====================
# Import Date Library
use Date::Calc qw (Date_to_Time Time_to_Date);
 
use Date::Calc qw (Date_to_Time Time_to_Date);
#=====================================
 
# MD5 Checksum und Zip-Funktionalität
#=====================================
# MD5 Checksum und Zip-Funktionalität
use Digest::MD5  qw(md5_hex);
 
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Digest::MD5  qw(md5_hex);
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
#================
 
# Encoding Stuff
#================
# Encoding Stuff
use Encode qw(encode decode);
 
my $encoding = 'utf-8';
use Encode qw(encode decode);
my $encOut;
 
$encOut  = 'cp1252'; # Windows Ansi
#=================
$encOut  = 'cp850' ; # DOS Fenster
# Hash for Months
 
#=================
my %month   = qw (Januar 01 Februar 02 März 03 April 04 Mai 05 Juni 06 Juli 07 August 08 September 09 Oktober 10 November 11 Dezember 12);
# Hash for Months
my %month_s = qw (Jan 01 Feb 02 Mär 03 Apr 04 Mai 05 Jun 06 Jul 07 Aug 08 Sep 09 Okt 10 Nov 11 Dez 12);
 
my %month = qw (Jan 01 Feb 02 Mär 03 Apr 04 Mai 05 Jun 06 Jul 07 Aug 08 Sep 09 Okt 10 Nov 11 Dez 12);
#==================
# Default Settings
#===========================
 
# Important Paths and Files
push @INC, '.';
 
require "ini.pl";
require "ini.pl";
my ($baseDir, $outDir, $username, $password) = getIni();
 
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
my $dir_txt  = "$baseDir/text";
 
my $dir_kmz  = "$baseDir/kmz";
my $dir_txt  = "$baseDir/text";
my $savePath = "$baseDir/upload";
my $dir_kmz  = "$baseDir/kmz";
my $savePath = "$baseDir/upload";
my $listFile = "RouteList.txt";
 
my $listFile = "RouteList.txt";
my $mech;            # Handle for mechanize-Browser
 
my $changesTxt  = 0;  # One or more Routefiles have changed
my $mech;            # Handle for mechanize-Browser
my $changesKmz  = 0;  # One or more KMZfiles have changed
my $changesTxt  = 0;  # One or more Routefiles have changed
my $changesKmz  = 0;  # One or more KMZfiles have changed
my @route    = ();    # Stores all Infos about Routes
 
my @routeNew = ();    # Keeps all new Infos for Saving
my @route    = ();    # Stores all Infos about Routes
my @routeNew = ();    # Keeps all new Infos for Saving
 
 
if ($updateDates or $updateRecent or $updateRoutes or $upload or $updateAllKMZ) {
 
if ($updateDates or $updateRecent or $updateRoutes or $upload or $updateAllKMZ) {
#=====================================================
 
# Initialisieren von Mechanize-Browser und Cookie-Jar
#=====================================================
# Initialisieren von Mechanize-Browser und Cookie-Jar
use WWW::Mechanize;
 
use HTTP::Cookies;
use WWW::Mechanize;
$mech = WWW::Mechanize->new( autocheck => 1 );
use HTTP::Cookies;
$mech->agent_alias( 'Windows Mozilla' );
$mech = WWW::Mechanize->new(  
my $cookie_jar = HTTP::Cookies->new( file => "cookies.txt", autosave => 1 );
ssl_opts => {
$mech->cookie_jar($cookie_jar);
SSL_verify_mode => '0',
verify_hostname => 0
#============================================================
}
# Einloggen ins Radreise-Wiki um in den Edit-Modus zu kommen
);
$mech->agent_alias( 'Windows Mozilla' );
$mech->get("http://www.radreise-wiki.de/Spezial:Userlogin");
my $cookie_jar = HTTP::Cookies->new( file => "cookies.txt", autosave => 1 );
$mech->form_number('1');
$mech->cookie_jar($cookie_jar);
$mech->field("wpName", $username);
 
$mech->field("wpPassword", $password);
#============================================================
$mech->tick('wpRemember', '1');
# Einloggen ins Radreise-Wiki um in den Edit-Modus zu kommen
$mech->click();
 
}
$mech->get('https://radreise-wiki.de/index.php?title=Spezial:Anmelden');
#==========================
$mech->form_number('1');
# Load Routelist from File
$mech->field("wpName1", $username);
$mech->field("wpPassword1", $password);
print "\nGetting Content from File: $listFile\n";
$mech->tick('wpRemember', '1');
$mech->click();
my $content;
}
 
open FIN, "$baseDir/$listFile" or die $!;
#==========================
# Load Routelist from File
while (<FIN>) {
 
print "\nReading $listFile\n";
my $line = decode $encoding, $_;
 
my $content;
if ($line =~ /^
 
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of txt-File
open FIN, "$baseDir/$listFile" or die $!;
\ ::\  
 
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of kmz-File
while (<FIN>) {
\ ::\  
 
([H|h|R|L|X])# Type
my $line = decode $encoding, $_;
\ ::\  
(.*)     # Routename
if ($line =~ /^
\ ::\
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of txt-File
(.*)    # RouteURL
\ ::\  
$/x) {
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of kmz-File
\ ::\  
my $year      =  $1;
([H|h|R|r|L|X])                                   # Type
my $month    =  $2;
\ ::\  
my $day      =  $3;
(.*)                                               # Routename
my $hour      =  $4;
$/x) {
my $min      =  $5;
my $sec      =  $6;
my $year      =  $1;
my $month    =  $2;
my $year_kmz  =  $7;
my $day      =  $3;
my $month_kmz =  $8;
my $hour      =  $4;
my $day_kmz  =  $9;
my $min      =  $5;
my $hour_kmz  = $10;
my $sec      =  $6;
my $min_kmz  = $11;
 
my $sec_kmz  = $12;
my $year_kmz  =  $7;
my $month_kmz =  $8;
my $type      = $13;
my $day_kmz  =  $9;
next if ($type eq "X");
my $hour_kmz  = $10;
my $min_kmz  = $11;
my $routeName = $14;
my $sec_kmz  = $12;
my $routeURL = $15;
 
my $type      = $13;
my $touch     = 0;
 
next if ($type eq "X");
if ( $updateDates ) {
 
my $routeName = $14;
#============================================
 
# Check Route- and KMZ-History Sites in Wiki
my $routeFileName = encode $encAnsi, $routeName;
 
$mech->get("http://radreise-wiki.de/index.php?title=$routeURL&action=history");
my $routeURL = encodeRouteNameURL($routeFileName);
my $website = $mech->content;
 
my @website = split "\n", $website;
my $touch = 0;
foreach my $l (@website) {
if ( $updateDates ) {
 
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4})</) {
#============================================
# Check Route- and KMZ-History Sites in Wiki
$hour  = $1;
 
$min  = $2;
$mech->get("http://radreise-wiki.de/index.php?title=$routeURL&action=history");
$sec  =  0;
my $website = $mech->content;
$day  = $3;
my @website = split "\n", $website;
$month = $month{$4};
 
$year  = $5;
foreach my $l (@website) {
 
last;
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4})</) {
}
 
}
$hour  = $1;
$min  = $2;
$mech->get("http://radreise-wiki.de/Bild:$routeURL.kmz");
$sec  =  0;
my $website = $mech->content;
$day  = $3;
my @website = split "\n", $website;
$month = $month{$4};
$year  = $5;
foreach my $l (@website) {
 
last;
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4}).*?\"Benutzer:(.*?)\"/) {
}
}
$hour_kmz  = $1;
 
$min_kmz  = $2;
$mech->get("http://radreise-wiki.de/Bild:$routeURL.kmz");
$sec_kmz  = 0;
my $website = $mech->content;
$day_kmz  = $3;
my @website = split "\n", $website;
$month_kmz = $month{$4};
 
$year_kmz  = $5;
foreach my $l (@website) {
 
my $user  = $6;
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4}).*?\"Benutzer:(.*?)\"/) {
 
print encode $encOut, "  $user : $routeName.kmz\n";
$hour_kmz  = $1;
$min_kmz  = $2;
last;
$sec_kmz  = 0;
}
$day_kmz  = $3;
}
$month_kmz = $month{$4};
}
$year_kmz  = $5;
 
my $routeNew = sprintf "%s-%s-%02d %s:%s:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s :: %s\n",  
my $user  = $6;
$year, $month, $day, $hour, $min, $sec,
 
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
print encode $encOut, "  $user : $routeName.kmz\n";
$type,
 
$routeName, $routeURL;
last;
}
my $mtime_txt = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
}
my $mtime_kmz = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);
}
 
my @zeile = ( $routeName, $routeURL, $mtime_txt, $mtime_kmz, $touch, $type );
my $routeNew = sprintf "%s-%s-%02d %s:%s:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
$year, $month, $day, $hour, $min, $sec,
my $ref_zeile = \@zeile;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
$type,
push @route  , $ref_zeile;
$routeName;
push @routeNew, $routeNew;
 
my $mtime_txt = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
} else {
my $mtime_kmz = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);
 
die "No Match in Line: $line\n";
my @zeile = ( $routeName, $routeURL, $mtime_txt, $mtime_kmz, $touch, $type );
}
}
my $ref_zeile = \@zeile;
close (FIN);
push @route  , $ref_zeile;
push @routeNew, $routeNew;
print "\n  ", $#route + 1, " Routes in List\n\n";
 
} else {
 
if ( $updateRecent ) {
die "No Match in Line: $line\n";
}
#======================================
}
# Checking for recently changed Routes
 
close (FIN);
print "Checking for recently changed Routes\n\n";
 
print "\n  ", $#route + 1, " Routes in List\n\n";
$mech->get("http://radreise-wiki.de/index.php?limit=250&title=Spezial%3ARecentchanges&namespace=0&limit=500&days=30");
 
 
my $website = $mech->content;
if ( $updateRecent ) {
 
my @website = split "\n", $website;
#======================================
# Checking for recently changed Routes
my $day;
 
my $month;
print "Checking for recently changed Routes\n\n";
my $year;
 
$mech->get("https://radreise-wiki.de/index.php?hidebots=1&namespace=0&limit=500&days=30&title=Spezial:Letzte_%C3%84nderungen&urlversion=2");
foreach my $line (@website) {
my $website = $mech->content;
if ($line =~ /<h4>(\d{1,2})\. (\w+) (\d{4})<\/h4>/) {
 
my @website = split "\n", $website;
$day  = $1;
 
$month = $month{$2};
my $day;
$year  = $3;
my $month;
my $year;
} elsif ($line =~ /<li>.*? title=\"([^\"]*)\".*?<\/a>; (\d{2}):(\d{2}) \. \. .*?title=\"Benutzer:(.*?)\".*?<\/li>/) {
 
foreach my $line (@website) {
my $title = $1;
 
my $hour  = $2;
# <h4>2014-06-14</h4>
my $min  = $3;
 
my $sec  = 0;
if ($line =~ /<h4>(\d{4})-(\d{2})-(\d{2})<\/h4>/) {
my $usr  = $4;
 
$year  = $1;
my $mtime = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
$month = $2;
$day  = $3;
for (my $j=0; $j<=$#route; $j++) {
 
#print "$year-$month-$day\n";
if ( ! $route[$j][4] and ($route[$j][0] eq $title) and ($mtime > $route[$j][2]) ) {
 
# data-target-page="Lahn"      date">21:26:43<
$route[$j][4] = 1;
} elsif ($line =~ /data-target-page=\"([^\"]*)\".*?date\">(\d{2}):(\d{2}):(\d{2})</) {
$changesTxt  = 1;
 
my $title = $1;
print encode $encOut, "$year-$month-$day $hour:$min : Update for $title ($usr)\n";
my $hour  = $2;
my $min  = $3;
my ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz) = Time_to_Date($route[$j][3]);
my $sec  = $4;
 
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s :: %s\n",  
#print "  $hour:$min:$sec $title\n";
$year, $month, $day, $hour, $min, $sec,
 
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
my $mtime = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
$route[$j][5],
 
$route[$j][0], $route[$j][1];
for (my $j=0; $j<=$#route; $j++) {
 
$routeNew[$j] = $routeNew;
if ( ! $route[$j][4] and ($route[$j][0] eq $title) and ($mtime > $route[$j][2]) ) {
}
 
}
$route[$j][4] = 1;
}
$changesTxt  = 1;
}
 
print encode $encOut, "$year-$month-$day $hour:$min : Update for $title\n";
if ($changesTxt) {
 
my ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz) = Time_to_Date($route[$j][3]);
print "\n";
 
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
} else {
$year, $month, $day, $hour, $min, $sec,
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
print "  No Changes\n\n";
$route[$j][5],
}
$route[$j][0];
 
#=========================================
$routeNew[$j] = $routeNew;
# Checking for recently changed KMZ-Files
}
}
print "Checking for recently changed KMZ-Files\n\n";
}
}
$mech->get("http://radreise-wiki.de/index.php?title=Spezial:Log&type=upload&user=&page=&limit=250&offset=0");
 
my $website = $mech->content;
if ($changesTxt) {
my @website = split "\n", $website;
 
print "\n";
foreach my $line (@website) {
 
} else {
if ($line =~ /
 
<li>
print "  No Changes\n\n";
(\d{2}):(\d{2}),\ (\d{1,2})\.\ (\w{3})\ (\d{4})
}
.*?
 
title=\"Benutzer:(.*?)\"
#=========================================
.*?
# Checking for recently changed KMZ-Files
title=\"Bild:(.*?)\.kmz
 
\".*
print "Checking for recently changed KMZ-Files\n\n";
<\/li>
 
/x) {
$mech->get("http://radreise-wiki.de/index.php?title=Spezial%3ALogbuch&type=upload&user=&page=&year=&month=-1");
my $website = $mech->content;
my $hour_kmz = $1;
my @website = split "\n", $website;
my $min_kmz  = $2;
 
my $sec_kmz  =  0;
foreach my $line (@website) {
my $day_kmz  = $3;
 
my $month_kmz = $month{$4};
if ($line =~ /
my $year_kmz  = $5;
<li\ class
my $user     = $6;
.*?
my $route    = $7;
(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})
.*?
my $mtime = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);
title=\"Benutzer:(.*?)\"
.*?
for (my $j=0; $j<=$#route; $j++) {
title=\"Datei:(.*?)\.kmz\"
.*
if ( ! $route[$j][4] and ($route[$j][0] eq $route) and ($mtime > $route[$j][3]) ) {
<\/li>
/x) {
#$route[$j][4] = 1;
 
$changesKmz    = 1;
my $year_kmz = $1;
my $month_kmz = $2;
print encode $encOut, "$year_kmz-$month_kmz-$day_kmz $hour_kmz:$min_kmz : Update for $route.kmz ($user)\n";
my $day_kmz  = $3;
my $hour_kmz  = $4;
my ($year,$month,$day, $hour,$min,$sec) = Time_to_Date($route[$j][2]);
my $min_kmz  = $5;
my $sec_kmz  = $6;
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s :: %s\n",  
my $user     = $7;
$year, $month, $day, $hour, $min, $sec,
my $route    = $8;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
 
$route[$j][5],
#print "$year_kmz-$month_kmz-$day_kmz :: $hour_kmz:$min_kmz :: $route :: $user\n";
$route[$j][0], $route[$j][1];
 
my $mtime = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);
$routeNew[$j] = $routeNew;
 
}
for (my $j=0; $j<=$#route; $j++) {
}
 
}
if ( ! $route[$j][4] and ($route[$j][0] eq $route) and ($mtime > $route[$j][3]) ) {
}
 
#$route[$j][4] = 1;
$changesKmz    = 1;
if ($changesTxt or $changesKmz or $updateDates) {
 
print encode $encOut, "$year_kmz-$month_kmz-$day_kmz $hour_kmz:$min_kmz : Update for $route.kmz ($user)\n";
#====================================
 
# Saving the new Listfile if changed
my ($year,$month,$day, $hour,$min,$sec) = Time_to_Date($route[$j][2]);
 
print "\n";
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
$year, $month, $day, $hour, $min, $sec,
my $routeNew = join "", @routeNew;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
$route[$j][5], $route[$j][0];
saveFileIfChangedOrNew ("$baseDir/", $listFile, encode $encoding, $routeNew, 0);
 
$routeNew[$j] = $routeNew;
print "\n";
}
}
} else {
}
}
print "  No Changes\n\n";
 
}
 
if ($changesTxt or $changesKmz or $updateDates) {
}
 
#====================================
if ($updateAllRoutes) {
# Saving the new Listfile if changed
 
#=======================
print "\n";
# Update all Routefiles
 
my $routeNew = join "", @routeNew;
print "Updating all Routefiles\n\n";
 
saveFileIfChangedOrNew ("$baseDir/", $listFile, encode $encoding, $routeNew, 0);
for (my $i=0; $i<=$#route; $i++) {
 
print "\n";
$route[$i][4] = 1;
 
}
} else {
}
 
print "  No Changes\n\n";
}
#====================================================
 
# Parsing of all Files in List and modify, if wanted
}
 
for (my $i=0; $i<=$#route; $i++) {
if ($updateAllRoutes) {
 
my $routeName = $route[$i][0];
#=======================
my $routeOut  = encode $encOut,  $routeName;
# Update all Routefiles
my $routeFile = encode 'cp1252', $routeName;
 
my $routeURL  = $route[$i][1];
print "Updating all Routefiles\n\n";
my $touch    = $route[$i][4];
 
my $type      = $route[$i][5];
for (my $i=0; $i<=$#route; $i++) {
 
if ($updateAllKMZ) {
$route[$i][4] = 1;
}
#=================================
}
# Update alle KMZ Files from Wiki
 
 
printf "%3d: Saving %s.kmz\n", $i+1, $routeOut;
#====================================================
# Parsing of all Files in List and modify, if wanted
$mech->get("http://www.radreise-wiki.de/images/$routeURL.kmz", ":content_file" => "$dir_kmz/$routeFile.kmz");
 
for (my $i=0; $i<=$#route; $i++) {
my $zip = Archive::Zip->new();
 
my $routeName = $route[$i][0];
my $status = $zip->read("$dir_kmz/$routeFile.kmz");
my $routeOut  = encode $encOut,  $routeName;
my $routeFile = encode $encAnsi, $routeName;
if ($status != AZ_OK) {
my $routeURL  = $route[$i][1];
my $touch    = $route[$i][4];
die "Error while reading KMZ file! $!";
my $type      = $route[$i][5];
 
} else {
if ($updateAllKMZ) {
 
my @members = $zip->memberNames();
#=================================
# Update alle KMZ Files from Wiki
if ($#members != 0) { die "Error: More than one File within kmz!\n"; }
 
printf "%3d: Saving %s.kmz\n", $i+1, $routeOut;
print encode $encOut, "    Renaming $members[0] -> $routeFile.kml\n";
 
$mech->get("http://www.radreise-wiki.de/images/$routeURL.kmz", ":content_file" => "$dir_kmz/$routeFile.kmz");
$zip->extractTree(undef, "$dir_kmz/");
 
my $zip = Archive::Zip->new();
rename("$dir_kmz/$members[0]","$dir_kmz/$routeFile.kml") || die "Error while Renaming File: $!";
 
my $status = $zip->read("$dir_kmz/$routeFile.kmz");
my $ucontent = "";
 
open FILE, encode 'cp1252', "$dir_kmz/$routeFile\.kml" or die $!;
if ($status != AZ_OK) {
while (<FILE>) { $ucontent .= $_; }
 
close FILE;
die "Error while reading KMZ file! $!";
my $content = decode $encoding, $ucontent;
 
} else {
if ($content =~ /<\/tessellate>\s*<coordinates>\s*(.*?)\s*<\/coordinates>/s) {
 
my @members = $zip->memberNames();
my $track = $1;
 
if ($#members != 0) { die "Error: More than one File within kmz!\n"; }
if ($track =~ /\n/) {
 
print encode $encOut, "    Renaming $members[0] -> $routeFile.kml\n";
die "Error: Linebreak within Track\n";
 
}
$zip->extractTree(undef, "$dir_kmz/");
 
print encode $encOut, "    Saving $routeFile.txt\n";
rename("$dir_kmz/$members[0]","$dir_kmz/$routeFile.kml") || die "Error while Renaming File: $!";
 
open FILE, ">$dir_kmz/$routeFile\.txt" or die $!;
if ($members[0] ne "doc.kml") {
print FILE $track;
 
close FILE;
if ($members[0] ne "$routeFile.kml") {
 
} else {
print "WARNING: $routeFile.kml -> $members[0]\n";
}
print "  Error: No Match in $routeName\n";
}
die;
 
}
my $ucontent = "";
}  
open FILE, encode $encAnsi, "$dir_kmz/$routeFile\.kml" or die $!;
}
while (<FILE>) { $ucontent .= $_; }
close FILE;
if ($updateRoutes and $touch) {
my $content = decode $encoding, $ucontent;
 
#========================================================
if ($content =~ /<\/tessellate>\s*<coordinates>\s*(.*?)\s*<\/coordinates>/s) {
# Update local Routefiles from Wiki if touch-Flag is set
 
my $track = $1;
printf "%3d: Saving %s\n", $i+1, $routeOut;
 
if ($track =~ /\n/) {
$mech->get("http://www.radreise-wiki.de/$routeURL");
 
my $website = $mech->content;
die "Error: Linebreak within Track\n";
}
# Gehe zum Editieren der Route
$mech->follow_link( url => "/index.php?title=$routeURL&action=edit" );
print encode $encOut, "    Saving $routeFile.txt\n";
$website = $mech->content;
 
open FILE, ">$dir_kmz/$routeFile\.txt" or die $!;
$website =~ /<textarea.*>(.*)<\/textarea>/s;
print FILE $track;
close FILE;
my $wikiText = $1;
 
} else {
$wikiText =~ s/&lt;/</g;
 
$wikiText =~ s/&gt;/>/g;
print "  Error: No Match in $routeName\n";
$wikiText =~ s/&quot;/\"/g;
die;
$wikiText =~ s/&amp;/\&/g;
}
}  
if (length $wikiText > 1) {
}
 
&saveFileIfChangedOrNew ("$dir_txt/", "$routeFile.txt", encode $encoding, $wikiText, 0);
if ($updateRoutes and $touch) {
 
# External Call. Exit Code : 0 - No Change, 1 - KML-File Changed
#========================================================
my $result = system("perl makeKML.pl $routeFile");
# Update local Routefiles from Wiki if touch-Flag is set
 
} else {
print "Trying to update $routeOut\n";
 
die "URL is not existent: $routeURL\n";
$mech->get("http://www.radreise-wiki.de/index.php?title=$routeURL&action=edit");
}
 
}
my $website = $mech->content;
 
my $newContent;
$website =~ /<textarea.*?>(.*)<\/textarea>/s;
 
if ($modify) {
my $wikiText = $1;
 
#=====================================================
$wikiText =~ s/&lt;/</g;
# Modify Routefile and save it to different directory
$wikiText =~ s/&gt;/>/g;
$wikiText =~ s/&quot;/\"/g;
my $ucontent = "";
$wikiText =~ s/&amp;/\&/g;
open FILE, encode 'cp1252', "$dir_txt/$routeName\.txt" or die $!;
 
while (<FILE>) { $ucontent .= $_; }
if (length $wikiText > 1) {
close FILE;
 
my $content = decode $encoding, $ucontent;
&saveFileIfChangedOrNew ("$dir_txt/", "$routeFile.txt", encode $encoding, $wikiText, 0);
 
my $match_1 = "";
# External Call. Exit Code : 0 - No Change, 1 - KML-File Changed
my $result = system("perl makeKML.pl $routeFile");
if ($content =~ /(Höhenmeter \(ab\) = [ 0-9\.]*\n)\}\}\n/) {
 
if (!$result) {
$match_1 = $1;
print "  No changes in KML-File\n\n";
} else {
} else {
print "\n";
}
print "  Error: No Match in $routeName\n";
 
die;
} else {
}
 
die "URL not found or Edit-Window is empty: >$routeURL<\n";
my $match_2 = "";
}
my $gegenrichtung = "Bild:Ohne Gegenrichtung.png";
}
 
if ($content =~ /(\n\{\{[RetT]+our\|[^\}].*\}\}\n)/) {
my $newContent;
 
$match_2 = $1;
if ($modify) {
 
if ($match_2 =~ /\n\{\{[RetT]+our\|([^\}].*)\}\}\n/) {
#=====================================================
# Modify Routefile and save it to upload-directory
$gegenrichtung = $1;
 
my $ucontent = "";
} else {
open FILE, encode $encAnsi, "$dir_txt/$routeName\.txt" or die $!;
while (<FILE>) { $ucontent .= $_; }
print "  Error: No Match in $routeName\n";
close FILE;
die;
my $content = decode $encoding, $ucontent;
}
 
}
my $match_1 = "";
 
my $replace_1 = "$match_1\| Tour-/Retour-Link = $gegenrichtung\n";
if ($content =~ /(Höhenmeter \(ab\) = [ 0-9\.]*\n)\}\}\n/) {
$replace_1 =~ s/  / /;
$replace_1 =~ s/Höhenmeter/Höhenmexer/;
$match_1 = $1;
 
if ($content =~ s/\Q$match_1/$replace_1/) {
} else {
 
} else {
print "  Error: No Match in $routeName\n";
print "No Match\n";
die;
die;
}
}
 
my $match_2 = "";
$content =~ s/\Q$match_2//;
my $gegenrichtung = "Bild:Ohne Gegenrichtung.png";
 
$content =~ s/ \n/\n/g;
if ($content =~ /(\n\{\{[RetT]+our\|[^\}].*\}\}\n)/) {
$content =~ s/ \n/\n/g;
$content =~ s/ \n/\n/g;
$match_2 = $1;
$content =~ s/Höhenmexer/Höhenmeter/;
 
if ($match_2 =~ /\n\{\{[RetT]+our\|([^\}].*)\}\}\n/) {
$newContent = $content;
 
$gegenrichtung = $1;
#print encode 'cp850', "  Saving $routeName\n";
 
} else {
open  FOUT, encode 'cp1252', "> $savePath/$routeName.txt" or die $!;
 
print FOUT encode ($encoding, $newContent);
print "  Error: No Match in $routeName\n";
close FOUT;
die;
}
}
}
if ($upload) {
 
my $replace_1 = "$match_1\| Tour-/Retour-Link = $gegenrichtung\n";
#==========================================
$replace_1 =~ s/  / /;
# UPLOAD CHANGED TEXTFILES TO THE WIKI !!!
$replace_1 =~ s/Höhenmeter/Höhenmexer/;
 
print encode ('cp850', "  Uploading $routeName to $routeURL\n");
if ($content =~ s/\Q$match_1/$replace_1/) {
 
$mech->get("http://www.radreise-wiki.de/$routeURL");
} else {
print "No Match\n";
$mech->follow_link( url => "/index.php?title=$routeURL&action=edit" );
die;
}
$mech->field( 'wpTextbox1', $newContent);
 
$mech->field( 'wpSummary' , "Test Wiki-Bot: Infobox Tour-/Retour-Link hinzugefügt" );
$content =~ s/\Q$match_2//;
$mech->submit;
 
}
$content =~ s/ \n/\n/g;
}
$content =~ s/ \n/\n/g;
$content =~ s/ \n/\n/g;
if ($changesTxt) {
$content =~ s/Höhenmexer/Höhenmeter/;
exit(1);
 
} else {
$newContent = $content;
exit(0);
 
}
#print encode $encOut, "  Saving $routeName\n";
 
#=======================================================
open  FOUT, encode $encAnsi, "> $savePath/$routeName.txt" or die $!;
#=======================================================
print FOUT encode ($encoding, $newContent);
close FOUT;
sub saveFileIfChangedOrNew {
}
 
(my $path, my $fileName, my $file, my $kmz) = @_;
if ($upload) {
 
my $change = 0;
#==========================================
# UPLOAD CHANGED TEXTFILES TO THE WIKI !!!
if (open(FILE, "< $path$fileName")) {
 
print encode $encOut, "  Uploading $routeName to $routeURL\n";
my $md5 = Digest::MD5->new;
 
while (<FILE>) {
$mech->get("http://www.radreise-wiki.de/$routeURL");
$md5->add($_);
 
}
$mech->follow_link( url => "/index.php?title=$routeURL&action=edit" );
close(FILE);
 
$mech->field( 'wpTextbox1', $newContent);
my $md5_old = $md5->hexdigest;
$mech->field( 'wpSummary' , "Test Wiki-Bot: Infobox Tour-/Retour-Link hinzugefügt" );
$mech->submit;
$md5 = Digest::MD5->new;
}
$md5->add($file);
}
my $md5_new = $md5->hexdigest;
 
if ($changesTxt) {
unless ($md5_old eq $md5_new) {
exit(1);
} else {
$change = 1;
exit(0);
print encode 'cp850', "****************** Overwriting File $fileName ******************\n";
}
open  FT,"> $path$fileName";
</nowiki>
print FT $file;
 
close FT;
[[Kategorie: Verwaltungs-Software]]
if ($kmz) {
my $zip = Archive::Zip->new();
$zip->addFile("$path$fileName",$fileName);
$fileName =~ s/\.kml/\.kmz/;
unless ( $zip->writeToFileNamed("$path$fileName") == AZ_OK ) {
  die 'write error';
}
}
}
} else {
$change = 1;
print encode 'cp850', "****************** Creating new file $fileName ******************\n";
open  FT,"> $path$fileName";
print FT $file;
close FT;
if ($kmz) {
my $zip = Archive::Zip->new();
$zip->addFile("$path$fileName",$fileName);
$fileName =~ s/\.kml/\.kmz/;
unless ( $zip->writeToFileNamed("$path$fileName") == AZ_OK ) {
  die 'write error';
}
}
}
return $change;
}
  </nowiki>

Aktuelle Version vom 5. Juli 2023, 08:31 Uhr

Das Perl-Skript Route-Management.pl enthält eine Vielzahl von Funktionen zur Wiki-Verwaltung. Beim Aufruf muss eine 6-stellige Binärzahl übergeben werden, die diese Funktionen kodiert. Die wichtigsten Anwendungen sind:

  • 0101000 Aktualisiere die kürzlich geänderten Streckendateien
  • 0011000 Lade alle Streckendateien herunter
  • 0010100 Lade alle Trackdateien herunter

Für die Einrichtung der Verwaltungssoftware sind die letzten zwei Funktionen wichtig. Im laufenden Betrieb ist es die erste Funktion.

Beispiel für einen Programmstart zum Update der Streckendateien:

perl Route-Management.pl 0101000

Quellcode des Skripts:

use strict;

my $flags;

if ($ARGV[0]) {

	$flags = $ARGV[0];

} else {

	$flags = "0101000";
}

my @flags = split //, $flags;

#=========================
# Control-Flags

# 0101000 Update only recently changed Routefiles - show changed Trackfiles
# 0010100 Update all Trackfiles - do this first and get kml-Files
# 0011000 Update all Routefiles
# 0010010 Modify all Routefiles
# 0010011 Modify and upload all Routefiles

my $updateDates     = $flags[0]; # 1 = Read all Route- and KMZ-History Pages and update 
								 #     Listfile Dates

my $updateRecent    = $flags[1]; # 1 = Only update Routefiles from Wiki Recent Changes Page
                                 # 0 = Update all Routefiles

my $updateAllRoutes = $flags[2]; # 1 = Treat all Routefiles
                                 # 0 = Only treat touched Routefiles

my $updateRoutes    = $flags[3]; # 1 = Update Routefiles from Wiki
                                 # 0 = Do not update Routefiles

my $updateAllKMZ    = $flags[4]; # 1 = Update KMZ Files from Wiki and extract the KML content

my $modify          = $flags[5]; # 1 = Modify Routefiles
my $upload          = $flags[6]; # 1 = Upload modified Routefiles to Wiki


#=====================
# Import Date Library

use Date::Calc qw (Date_to_Time Time_to_Date);

#=====================================
# MD5 Checksum und Zip-Funktionalität

use Digest::MD5  qw(md5_hex);
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

#================
# Encoding Stuff

use Encode qw(encode decode);

#=================
# Hash for Months

my %month   = qw (Januar 01 Februar 02 März 03 April 04 Mai 05 Juni 06 Juli 07 August 08 September 09 Oktober 10 November 11 Dezember 12);
my %month_s = qw (Jan 01 Feb 02 Mär 03 Apr 04 Mai 05 Jun 06 Jul 07 Aug 08 Sep 09 Okt 10 Nov 11 Dez 12);

#==================
# Default Settings

push @INC, '.';

require "ini.pl";

my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();

my $dir_txt  = "$baseDir/text";
my $dir_kmz  = "$baseDir/kmz";
my $savePath = "$baseDir/upload";

my $listFile = "RouteList.txt";

my $mech;             # Handle for mechanize-Browser
my $changesTxt  = 0;  # One or more Routefiles have changed
my $changesKmz  = 0;  # One or more KMZfiles have changed

my @route    = ();    # Stores all Infos about Routes
my @routeNew = ();    # Keeps all new Infos for Saving



if ($updateDates or $updateRecent or $updateRoutes or $upload or $updateAllKMZ) {

	#=====================================================
	# Initialisieren von Mechanize-Browser und Cookie-Jar

	use WWW::Mechanize;
	use HTTP::Cookies;
	$mech = WWW::Mechanize->new( 
		ssl_opts => {
			SSL_verify_mode => '0',
			verify_hostname => 0
		} 
	);
	$mech->agent_alias( 'Windows Mozilla' );
	my $cookie_jar = HTTP::Cookies->new( file => "cookies.txt", autosave => 1 );
	$mech->cookie_jar($cookie_jar);

	#============================================================
	# Einloggen ins Radreise-Wiki um in den Edit-Modus zu kommen

	$mech->get('https://radreise-wiki.de/index.php?title=Spezial:Anmelden');
	
	$mech->form_number('1');
	$mech->field("wpName1", $username);
	$mech->field("wpPassword1", $password);
	$mech->tick('wpRemember', '1');
	$mech->click();
}

#==========================
# Load Routelist from File

print "\nReading $listFile\n";

my $content;

open FIN, "$baseDir/$listFile" or die $!;

while (<FIN>) {

	my $line = decode $encoding, $_;
	
	if ($line =~ /^
		(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})   # mtime of txt-File
		\ ::\ 
		(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})   # mtime of kmz-File
		\ ::\ 
		([H|h|R|r|L|X])                                    # Type
		\ ::\ 
		(.*)                                               # Routename
		$/x) {
	
		my $year      =  $1;
		my $month     =  $2;
		my $day       =  $3;
		my $hour      =  $4;
		my $min       =  $5;
		my $sec       =  $6;

		my $year_kmz  =  $7;
		my $month_kmz =  $8;
		my $day_kmz   =  $9;
		my $hour_kmz  = $10;
		my $min_kmz   = $11;
		my $sec_kmz   = $12;

		my $type      = $13;

		next if ($type eq "X");

		my $routeName = $14;

		my $routeFileName = encode $encAnsi, $routeName;

		my $routeURL = encodeRouteNameURL($routeFileName);

		my $touch = 0;
		
		if ( $updateDates ) {

			#============================================
			# Check Route- and KMZ-History Sites in Wiki

			$mech->get("http://radreise-wiki.de/index.php?title=$routeURL&action=history");
			my $website = $mech->content;
			my @website = split "\n", $website;

			foreach my $l (@website) {

				if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4})</) {

					$hour  = $1;
					$min   = $2;
					$sec   =  0;
					$day   = $3;
					$month = $month{$4};
					$year  = $5;

					last;
				}
			}

			$mech->get("http://radreise-wiki.de/Bild:$routeURL.kmz");
			my $website = $mech->content;
			my @website = split "\n", $website;

			foreach my $l (@website) {

				if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4}).*?\"Benutzer:(.*?)\"/) {

					$hour_kmz  = $1;
					$min_kmz   = $2;
					$sec_kmz   = 0;
					$day_kmz   = $3;
					$month_kmz = $month{$4};
					$year_kmz  = $5;

					my $user   = $6;

					print encode $encOut, "   $user : $routeName.kmz\n";

					last;
				}
			}
		}

		my $routeNew = sprintf "%s-%s-%02d %s:%s:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n", 
			$year, $month, $day, $hour, $min, $sec,
			$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
			$type,
			$routeName;

		my $mtime_txt = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
		my $mtime_kmz = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);

		my @zeile = ( $routeName, $routeURL, $mtime_txt, $mtime_kmz, $touch, $type );
		
		my $ref_zeile = \@zeile;
		
		push @route   , $ref_zeile;
		push @routeNew, $routeNew;

	} else {

		die "No Match in Line: $line\n";
	}
}

close (FIN);

print "\n   ", $#route + 1, " Routes in List\n\n";


if ( $updateRecent ) {

	#======================================
	# Checking for recently changed Routes

	print "Checking for recently changed Routes\n\n";

	$mech->get("https://radreise-wiki.de/index.php?hidebots=1&namespace=0&limit=500&days=30&title=Spezial:Letzte_%C3%84nderungen&urlversion=2");
		
	my $website = $mech->content;

	my @website = split "\n", $website;

	my $day;
	my $month;
	my $year;

	foreach my $line (@website) {

		# <h4>2014-06-14</h4>

		if ($line =~ /<h4>(\d{4})-(\d{2})-(\d{2})<\/h4>/) {

			$year  = $1;
			$month = $2;
			$day   = $3;

			#print "$year-$month-$day\n";

		# data-target-page="Lahn"       date">21:26:43<
		} elsif ($line =~ /data-target-page=\"([^\"]*)\".*?date\">(\d{2}):(\d{2}):(\d{2})</) {

			my $title = $1;
			my $hour  = $2;
			my $min   = $3;
			my $sec   = $4;

			#print "   $hour:$min:$sec $title\n";

			my $mtime = Date_to_Time ($year,$month,$day, $hour,$min,$sec);

			for (my $j=0; $j<=$#route; $j++) {

				if ( ! $route[$j][4] and ($route[$j][0] eq $title) and ($mtime > $route[$j][2]) ) {

					$route[$j][4] = 1;
					$changesTxt   = 1;

					print encode $encOut, "$year-$month-$day $hour:$min : Update for $title\n";

					my ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz) = Time_to_Date($route[$j][3]);

					my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n", 
						$year, $month, $day, $hour, $min, $sec,
						$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
						$route[$j][5],
						$route[$j][0];

					$routeNew[$j] = $routeNew;
				}
			}
		}
	}

	if ($changesTxt) {

		print "\n";

	} else {

		print "   No Changes\n\n";
	}

	#=========================================
	# Checking for recently changed KMZ-Files

	print "Checking for recently changed KMZ-Files\n\n";

	$mech->get("http://radreise-wiki.de/index.php?title=Spezial%3ALogbuch&type=upload&user=&page=&year=&month=-1");
	my $website = $mech->content;
	my @website = split "\n", $website;

	foreach my $line (@website) {

		if ($line =~ /
				<li\ class
				.*?
				(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})
				.*?
				title=\"Benutzer:(.*?)\"
				.*?
				title=\"Datei:(.*?)\.kmz\"
				.*
				<\/li>
			/x) {

			my $year_kmz  = $1;
			my $month_kmz = $2;
			my $day_kmz   = $3;
			my $hour_kmz  = $4;
			my $min_kmz   = $5;
			my $sec_kmz   = $6;
			my $user      = $7;
			my $route     = $8;

			#print "$year_kmz-$month_kmz-$day_kmz :: $hour_kmz:$min_kmz :: $route :: $user\n";

			my $mtime = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);

			for (my $j=0; $j<=$#route; $j++) {

				if ( ! $route[$j][4] and ($route[$j][0] eq $route) and ($mtime > $route[$j][3]) ) {

					#$route[$j][4] = 1;
					$changesKmz    = 1;

					print encode $encOut, "$year_kmz-$month_kmz-$day_kmz $hour_kmz:$min_kmz : Update for $route.kmz ($user)\n";

					my ($year,$month,$day, $hour,$min,$sec) = Time_to_Date($route[$j][2]);

					my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n", 
						$year, $month, $day, $hour, $min, $sec,
						$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
						$route[$j][5], $route[$j][0];

					$routeNew[$j] = $routeNew;
				}
			}
		}
	}


	if ($changesTxt or $changesKmz or $updateDates) {

		#====================================
		# Saving the new Listfile if changed

		print "\n";

		my $routeNew = join "", @routeNew;

		saveFileIfChangedOrNew ("$baseDir/", $listFile, encode $encoding, $routeNew, 0);

		print "\n";

	} else {

		print "   No Changes\n\n";
	}

}

if ($updateAllRoutes) {

	#=======================
	# Update all Routefiles

	print "Updating all Routefiles\n\n";

	for (my $i=0; $i<=$#route; $i++) {

		$route[$i][4] = 1;
	}
}


#====================================================
# Parsing of all Files in List and modify, if wanted

for (my $i=0; $i<=$#route; $i++) {

	my $routeName = $route[$i][0];
	my $routeOut  = encode $encOut,  $routeName;
	my $routeFile = encode $encAnsi, $routeName;
	my $routeURL  = $route[$i][1];
	my $touch     = $route[$i][4];
	my $type      = $route[$i][5];

	if ($updateAllKMZ) {

		#=================================
		# Update alle KMZ Files from Wiki

		printf "%3d: Saving %s.kmz\n", $i+1, $routeOut;

		$mech->get("http://www.radreise-wiki.de/images/$routeURL.kmz", ":content_file" => "$dir_kmz/$routeFile.kmz");

		my $zip = Archive::Zip->new();

		my $status = $zip->read("$dir_kmz/$routeFile.kmz");

		if ($status != AZ_OK) {

			die "Error while reading KMZ file! $!";

		} else {

			my @members = $zip->memberNames();

			if ($#members != 0) { die "Error: More than one File within kmz!\n"; }

			print encode $encOut, "     Renaming $members[0] -> $routeFile.kml\n";

			$zip->extractTree(undef, "$dir_kmz/");

			rename("$dir_kmz/$members[0]","$dir_kmz/$routeFile.kml") || die "Error while Renaming File: $!";

			if ($members[0] ne "doc.kml") {

				if ($members[0] ne "$routeFile.kml") {

					print "WARNING: $routeFile.kml -> $members[0]\n";
				}
			}

			my $ucontent = "";
			open FILE, encode $encAnsi, "$dir_kmz/$routeFile\.kml" or die $!;
			while (<FILE>) { $ucontent .= $_; }
			close FILE;
			my $content = decode $encoding, $ucontent;

			if ($content =~ /<\/tessellate>\s*<coordinates>\s*(.*?)\s*<\/coordinates>/s) {

				my $track = $1;

				if ($track =~ /\n/) {

					die "Error: Linebreak within Track\n";
				}
				
				print encode $encOut, "     Saving $routeFile.txt\n";

				open FILE, ">$dir_kmz/$routeFile\.txt" or die $!;
				print FILE $track;
				close FILE;

			} else {

				print "   Error: No Match in $routeName\n";
				die;
			}
		} 
	}

	if ($updateRoutes and $touch) {

		#========================================================
		# Update local Routefiles from Wiki if touch-Flag is set

		print "Trying to update $routeOut\n";

		$mech->get("http://www.radreise-wiki.de/index.php?title=$routeURL&action=edit");

		my $website = $mech->content;

		$website =~ /<textarea.*?>(.*)<\/textarea>/s;

		my $wikiText = $1;

		$wikiText =~ s/</</g;
		$wikiText =~ s/>/>/g;
		$wikiText =~ s/"/\"/g;
		$wikiText =~ s/&/\&/g;

		if (length $wikiText > 1) {

			&saveFileIfChangedOrNew ("$dir_txt/", "$routeFile.txt", encode $encoding, $wikiText, 0);

			# External Call. Exit Code : 0 - No Change, 1 - KML-File Changed
			my $result = system("perl makeKML.pl $routeFile");

			if (!$result) {
				print "   No changes in KML-File\n\n";
			} else {
				print "\n";
			}

		} else {

			die "URL not found or Edit-Window is empty: >$routeURL<\n";
		}
	}

	my $newContent;

	if ($modify) {

		#=====================================================
		# Modify Routefile and save it to upload-directory

		my $ucontent = "";
		open FILE, encode $encAnsi, "$dir_txt/$routeName\.txt" or die $!;
		while (<FILE>) { $ucontent .= $_; }
		close FILE;
		my $content = decode $encoding, $ucontent;

		my $match_1 = "";

		if ($content =~ /(Höhenmeter \(ab\) = [ 0-9\.]*\n)\}\}\n/) {
		
			$match_1 = $1;

		} else {

			print "   Error: No Match in $routeName\n";
			die;
		}

		my $match_2 = "";
		my $gegenrichtung = "Bild:Ohne Gegenrichtung.png";

		if ($content =~ /(\n\{\{[RetT]+our\|[^\}].*\}\}\n)/) {
		
			$match_2 = $1;

			if ($match_2 =~ /\n\{\{[RetT]+our\|([^\}].*)\}\}\n/) {

				$gegenrichtung = $1;

			} else {

				print "   Error: No Match in $routeName\n";
				die;
			}
		}

		my $replace_1 = "$match_1\| Tour-/Retour-Link = $gegenrichtung\n";
		$replace_1 =~ s/  / /;
		$replace_1 =~ s/Höhenmeter/Höhenmexer/;

		if ($content =~ s/\Q$match_1/$replace_1/) {

		} else {
			print "No Match\n";
			die;
		}

		$content =~ s/\Q$match_2//;

		$content =~ s/ \n/\n/g;
		$content =~ s/ \n/\n/g;
		$content =~ s/ \n/\n/g;
		$content =~ s/Höhenmexer/Höhenmeter/;

		$newContent = $content;

		#print encode $encOut, "   Saving $routeName\n";

		open  FOUT, encode $encAnsi, "> $savePath/$routeName.txt" or die $!;
		print FOUT encode ($encoding, $newContent);
		close FOUT;
	}

	if ($upload) {

		#==========================================
		# UPLOAD CHANGED TEXTFILES TO THE WIKI !!!

		print encode $encOut, "   Uploading $routeName to $routeURL\n";

		$mech->get("http://www.radreise-wiki.de/$routeURL");

		$mech->follow_link( url => "/index.php?title=$routeURL&action=edit" );

		$mech->field( 'wpTextbox1', $newContent);
		$mech->field( 'wpSummary' , "Test Wiki-Bot: Infobox Tour-/Retour-Link hinzugefügt" );
		$mech->submit;
	}
}

if ($changesTxt) {
	exit(1);
} else {
	exit(0);
}