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

Aus Radreise-Wiki
 
(10 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 14: Zeile 14:


  <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);
 
use Encode qw(encode decode);
#=================
 
# Hash for Months
#=================
# Hash for Months
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);
 
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
 
#==================
require "ini.pl";
# Default Settings
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
 
push @INC, '.';
my $dir_txt  = "$baseDir/text";
 
my $dir_kmz  = "$baseDir/kmz";
require "ini.pl";
my $savePath = "$baseDir/upload";
 
my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
my $listFile = "RouteList.txt";
 
my $dir_txt  = "$baseDir/text";
my $mech;            # Handle for mechanize-Browser
my $dir_kmz  = "$baseDir/kmz";
my $changesTxt  = 0;  # One or more Routefiles have changed
my $savePath = "$baseDir/upload";
my $changesKmz  = 0;  # One or more KMZfiles have changed
 
my $listFile = "RouteList.txt";
my @route    = ();    # Stores all Infos about Routes
 
my @routeNew = ();    # Keeps all new Infos for Saving
my $mech;            # Handle for mechanize-Browser
my $changesTxt  = 0;  # One or more Routefiles have changed
my $changesKmz  = 0;  # One or more KMZfiles have changed
 
if ($updateDates or $updateRecent or $updateRoutes or $upload or $updateAllKMZ) {
my @route    = ();    # Stores all Infos about Routes
my @routeNew = ();    # Keeps all new Infos for Saving
#=====================================================
 
# Initialisieren von Mechanize-Browser und Cookie-Jar
 
 
use WWW::Mechanize;
if ($updateDates or $updateRecent or $updateRoutes or $upload or $updateAllKMZ) {
use HTTP::Cookies;
 
$mech = WWW::Mechanize->new( autocheck => 1 );
#=====================================================
$mech->agent_alias( 'Windows Mozilla' );
# Initialisieren von Mechanize-Browser und Cookie-Jar
my $cookie_jar = HTTP::Cookies->new( file => "cookies.txt", autosave => 1 );
 
$mech->cookie_jar($cookie_jar);
use WWW::Mechanize;
use HTTP::Cookies;
#============================================================
$mech = WWW::Mechanize->new(  
# Einloggen ins Radreise-Wiki um in den Edit-Modus zu kommen
ssl_opts => {
SSL_verify_mode => '0',
$mech->get("http://www.radreise-wiki.de/Spezial:Userlogin");
verify_hostname => 0
$mech->form_number('1');
}
$mech->field("wpName", $username);
);
$mech->field("wpPassword", $password);
$mech->agent_alias( 'Windows Mozilla' );
$mech->tick('wpRemember', '1');
my $cookie_jar = HTTP::Cookies->new( file => "cookies.txt", autosave => 1 );
$mech->click();
$mech->cookie_jar($cookie_jar);
}
 
#============================================================
#==========================
# Einloggen ins Radreise-Wiki um in den Edit-Modus zu kommen
# Load Routelist from File
 
$mech->get('https://radreise-wiki.de/index.php?title=Spezial:Anmelden');
print "\nReading $listFile\n";
$mech->form_number('1');
my $content;
$mech->field("wpName1", $username);
$mech->field("wpPassword1", $password);
open FIN, "$baseDir/$listFile" or die $!;
$mech->tick('wpRemember', '1');
$mech->click();
while (<FIN>) {
}
 
my $line = decode $encoding, $_;
#==========================
# Load Routelist from File
if ($line =~ /^
 
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of txt-File
print "\nReading $listFile\n";
\ ::\  
 
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of kmz-File
my $content;
\ ::\  
 
([H|h|R|L|X])                                     # Type
open FIN, "$baseDir/$listFile" or die $!;
\ ::\  
 
(.*)                                              # Routename
while (<FIN>) {
$/x) {
 
my $line = decode $encoding, $_;
my $year      =  $1;
my $month    =  $2;
if ($line =~ /^
my $day      =  $3;
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of txt-File
my $hour      =  $4;
\ ::\  
my $min      =  $5;
(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})  # mtime of kmz-File
my $sec      =  $6;
\ ::\  
([H|h|R|r|L|X])                                   # Type
my $year_kmz  =  $7;
\ ::\  
my $month_kmz =  $8;
(.*)                                              # Routename
my $day_kmz  =  $9;
$/x) {
my $hour_kmz  = $10;
my $min_kmz  = $11;
my $year      =  $1;
my $sec_kmz  = $12;
my $month    =  $2;
my $day      =  $3;
my $type      = $13;
my $hour      =  $4;
next if ($type eq "X");
my $min      =  $5;
my $sec      =  $6;
my $routeName = $14;
 
my $year_kmz  =  $7;
my $routeFileName = encode $encAnsi, $routeName;
my $month_kmz =  $8;
my $day_kmz  =  $9;
my $routeURL = encodeRouteNameURL($routeFileName);
my $hour_kmz  = $10;
my $min_kmz  = $11;
my $touch = 0;
my $sec_kmz  = $12;
 
if ( $updateDates ) {
my $type      = $13;
 
#============================================
next if ($type eq "X");
# Check Route- and KMZ-History Sites in Wiki
 
my $routeName = $14;
$mech->get("http://radreise-wiki.de/index.php?title=$routeURL&action=history");
 
my $website = $mech->content;
my $routeFileName = encode $encAnsi, $routeName;
my @website = split "\n", $website;
 
my $routeURL = encodeRouteNameURL($routeFileName);
foreach my $l (@website) {
 
my $touch = 0;
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4})</) {
if ( $updateDates ) {
$hour  = $1;
 
$min  = $2;
#============================================
$sec  =  0;
# Check Route- and KMZ-History Sites in Wiki
$day  = $3;
 
$month = $month{$4};
$mech->get("http://radreise-wiki.de/index.php?title=$routeURL&action=history");
$year  = $5;
my $website = $mech->content;
my @website = split "\n", $website;
last;
 
}
foreach my $l (@website) {
}
 
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4})</) {
$mech->get("http://radreise-wiki.de/Bild:$routeURL.kmz");
 
my $website = $mech->content;
$hour  = $1;
my @website = split "\n", $website;
$min  = $2;
$sec  =  0;
foreach my $l (@website) {
$day  = $3;
$month = $month{$4};
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4}).*?\"Benutzer:(.*?)\"/) {
$year  = $5;
 
$hour_kmz  = $1;
last;
$min_kmz  = $2;
}
$sec_kmz  = 0;
}
$day_kmz  = $3;
 
$month_kmz = $month{$4};
$mech->get("http://radreise-wiki.de/Bild:$routeURL.kmz");
$year_kmz  = $5;
my $website = $mech->content;
my @website = split "\n", $website;
my $user  = $6;
 
foreach my $l (@website) {
print encode $encOut, "  $user : $routeName.kmz\n";
 
if ($l =~ />(\d{2}):(\d{2}), (\d{1,2})\. (\w{3}) (\d{4}).*?\"Benutzer:(.*?)\"/) {
last;
 
}
$hour_kmz  = $1;
}
$min_kmz  = $2;
}
$sec_kmz  = 0;
$day_kmz  = $3;
my $routeNew = sprintf "%s-%s-%02d %s:%s:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
$month_kmz = $month{$4};
$year, $month, $day, $hour, $min, $sec,
$year_kmz  = $5;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
 
$type,
my $user  = $6;
$routeName;
 
print encode $encOut, "  $user : $routeName.kmz\n";
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);
last;
}
my @zeile = ( $routeName, $routeURL, $mtime_txt, $mtime_kmz, $touch, $type );
}
}
my $ref_zeile = \@zeile;
 
my $routeNew = sprintf "%s-%s-%02d %s:%s:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
push @route  , $ref_zeile;
$year, $month, $day, $hour, $min, $sec,
push @routeNew, $routeNew;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
$type,
} else {
$routeName;
 
die "No Match in Line: $line\n";
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 );
close (FIN);
my $ref_zeile = \@zeile;
print "\n  ", $#route + 1, " Routes in List\n\n";
push @route  , $ref_zeile;
push @routeNew, $routeNew;
if ( $updateRecent ) {
 
} else {
#======================================
 
# Checking for recently changed Routes
die "No Match in Line: $line\n";
}
print "Checking for recently changed Routes\n\n";
}
 
$mech->get("http://radreise-wiki.de/index.php?limit=250&title=Spezial%3ARecentchanges&namespace=0&limit=500&days=30");
close (FIN);
 
my $website = $mech->content;
print "\n  ", $#route + 1, " Routes in List\n\n";
 
my @website = split "\n", $website;
 
if ( $updateRecent ) {
my $day;
 
my $month;
#======================================
my $year;
# Checking for recently changed Routes
 
foreach my $line (@website) {
print "Checking for recently changed Routes\n\n";
 
if ($line =~ /<h4>(\d{1,2})\. (\w+) (\d{4})<\/h4>/) {
$mech->get("https://radreise-wiki.de/index.php?hidebots=1&namespace=0&limit=500&days=30&title=Spezial:Letzte_%C3%84nderungen&urlversion=2");
$day  = $1;
my $website = $mech->content;
$month = $month{$2};
 
$year  = $3;
my @website = split "\n", $website;
 
} elsif ($line =~ /<li>.*? title=\"([^\"]*)\".*?<\/a>; (\d{2}):(\d{2}) \. \. .*?title=\"Benutzer:(.*?)\".*?<\/li>/) {
my $day;
my $month;
my $title = $1;
my $year;
my $hour  = $2;
 
my $min  = $3;
foreach my $line (@website) {
my $sec  = 0;
 
my $usr  = $4;
# <h4>2014-06-14</h4>
 
my $mtime = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
if ($line =~ /<h4>(\d{4})-(\d{2})-(\d{2})<\/h4>/) {
 
for (my $j=0; $j<=$#route; $j++) {
$year  = $1;
$month = $2;
if ( ! $route[$j][4] and ($route[$j][0] eq $title) and ($mtime > $route[$j][2]) ) {
$day  = $3;
 
$route[$j][4] = 1;
#print "$year-$month-$day\n";
$changesTxt  = 1;
 
# data-target-page="Lahn"      date">21:26:43<
print encode $encOut, "$year-$month-$day $hour:$min : Update for $title ($usr)\n";
} elsif ($line =~ /data-target-page=\"([^\"]*)\".*?date\">(\d{2}):(\d{2}):(\d{2})</) {
 
my ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz) = Time_to_Date($route[$j][3]);
my $title = $1;
my $hour  = $2;
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
my $min  = $3;
$year, $month, $day, $hour, $min, $sec,
my $sec  = $4;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
 
$route[$j][5],
#print "  $hour:$min:$sec $title\n";
$route[$j][0];
 
my $mtime = Date_to_Time ($year,$month,$day, $hour,$min,$sec);
$routeNew[$j] = $routeNew;
 
}
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;
if ($changesTxt) {
$changesTxt  = 1;
 
print "\n";
print encode $encOut, "$year-$month-$day $hour:$min : Update for $title\n";
 
} else {
my ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz) = Time_to_Date($route[$j][3]);
 
print "  No Changes\n\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,
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
#=========================================
$route[$j][5],
# Checking for recently changed KMZ-Files
$route[$j][0];
 
print "Checking for recently changed KMZ-Files\n\n";
$routeNew[$j] = $routeNew;
}
$mech->get("http://radreise-wiki.de/index.php?title=Spezial:Log&type=upload&user=&page=&limit=250&offset=0");
}
my $website = $mech->content;
}
my @website = split "\n", $website;
}
 
foreach my $line (@website) {
if ($changesTxt) {
 
if ($line =~ /
print "\n";
<li>
 
(\d{2}):(\d{2}),\ (\d{1,2})\.\ (\w{3})\ (\d{4})
} else {
.*?
 
title=\"Benutzer:(.*?)\"
print "  No Changes\n\n";
.*?
}
title=\"Bild:(.*?)\.kmz
 
\".*
#=========================================
<\/li>
# Checking for recently changed KMZ-Files
/x) {
 
print "Checking for recently changed KMZ-Files\n\n";
my $hour_kmz = $1;
 
my $min_kmz  = $2;
$mech->get("http://radreise-wiki.de/index.php?title=Spezial%3ALogbuch&type=upload&user=&page=&year=&month=-1");
my $sec_kmz   = 0;
my $website = $mech->content;
my $day_kmz  = $3;
my @website = split "\n", $website;
my $month_kmz = $month{$4};
 
my $year_kmz  = $5;
foreach my $line (@website) {
my $user      = $6;
 
my $route    = $7;
if ($line =~ /
<li\ class
my $mtime = Date_to_Time ($year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz);
.*?
(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})
for (my $j=0; $j<=$#route; $j++) {
.*?
title=\"Benutzer:(.*?)\"
if ( ! $route[$j][4] and ($route[$j][0] eq $route) and ($mtime > $route[$j][3]) ) {
.*?
title=\"Datei:(.*?)\.kmz\"
#$route[$j][4] = 1;
.*
$changesKmz    = 1;
<\/li>
/x) {
print encode $encOut, "$year_kmz-$month_kmz-$day_kmz $hour_kmz:$min_kmz : Update for $route.kmz ($user)\n";
 
my $year_kmz = $1;
my ($year,$month,$day, $hour,$min,$sec) = Time_to_Date($route[$j][2]);
my $month_kmz = $2;
my $day_kmz   = $3;
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
my $hour_kmz  = $4;
$year, $month, $day, $hour, $min, $sec,
my $min_kmz  = $5;
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
my $sec_kmz  = $6;
$route[$j][5], $route[$j][0];
my $user      = $7;
my $route    = $8;
$routeNew[$j] = $routeNew;
 
}
#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 ($changesTxt or $changesKmz or $updateDates) {
if ( ! $route[$j][4] and ($route[$j][0] eq $route) and ($mtime > $route[$j][3]) ) {
 
#====================================
#$route[$j][4] = 1;
# Saving the new Listfile if changed
$changesKmz    = 1;
 
print "\n";
print encode $encOut, "$year_kmz-$month_kmz-$day_kmz $hour_kmz:$min_kmz : Update for $route.kmz ($user)\n";
 
my $routeNew = join "", @routeNew;
my ($year,$month,$day, $hour,$min,$sec) = Time_to_Date($route[$j][2]);
 
saveFileIfChangedOrNew ("$baseDir/", $listFile, encode $encoding, $routeNew, 0);
my $routeNew = sprintf "%s-%02d-%02d %02d:%02d:%02d :: %s-%02d-%02d %02d:%02d:%02d :: %s :: %s\n",  
$year, $month, $day, $hour, $min, $sec,
print "\n";
$year_kmz,$month_kmz,$day_kmz, $hour_kmz,$min_kmz,$sec_kmz,
$route[$j][5], $route[$j][0];
} else {
 
$routeNew[$j] = $routeNew;
print "  No Changes\n\n";
}
}
}
}
}
}
 
if ($updateAllRoutes) {
 
if ($changesTxt or $changesKmz or $updateDates) {
#=======================
 
# Update all Routefiles
#====================================
# Saving the new Listfile if changed
print "Updating all Routefiles\n\n";
 
print "\n";
for (my $i=0; $i<=$#route; $i++) {
 
my $routeNew = join "", @routeNew;
$route[$i][4] = 1;
 
}
saveFileIfChangedOrNew ("$baseDir/", $listFile, encode $encoding, $routeNew, 0);
}
 
print "\n";
 
#====================================================
} else {
# Parsing of all Files in List and modify, if wanted
 
print "  No Changes\n\n";
for (my $i=0; $i<=$#route; $i++) {
}
 
my $routeName = $route[$i][0];
}
my $routeOut  = encode $encOut,  $routeName;
 
my $routeFile = encode $encAnsi, $routeName;
if ($updateAllRoutes) {
my $routeURL  = $route[$i][1];
 
my $touch    = $route[$i][4];
#=======================
my $type      = $route[$i][5];
# Update all Routefiles
 
if ($updateAllKMZ) {
print "Updating all Routefiles\n\n";
 
#=================================
for (my $i=0; $i<=$#route; $i++) {
# Update alle KMZ Files from Wiki
 
$route[$i][4] = 1;
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();
#====================================================
# Parsing of all Files in List and modify, if wanted
my $status = $zip->read("$dir_kmz/$routeFile.kmz");
 
for (my $i=0; $i<=$#route; $i++) {
if ($status != AZ_OK) {
 
my $routeName = $route[$i][0];
die "Error while reading KMZ file! $!";
my $routeOut  = encode $encOut,  $routeName;
my $routeFile = encode $encAnsi, $routeName;
} else {
my $routeURL  = $route[$i][1];
my $touch    = $route[$i][4];
my @members = $zip->memberNames();
my $type      = $route[$i][5];
 
if ($#members != 0) { die "Error: More than one File within kmz!\n"; }
if ($updateAllKMZ) {
 
print encode $encOut, "    Renaming $members[0] -> $routeFile.kml\n";
#=================================
# Update alle KMZ Files from Wiki
$zip->extractTree(undef, "$dir_kmz/");
 
printf "%3d: Saving %s.kmz\n", $i+1, $routeOut;
rename("$dir_kmz/$members[0]","$dir_kmz/$routeFile.kml") || die "Error while Renaming File: $!";
 
$mech->get("http://www.radreise-wiki.de/images/$routeURL.kmz", ":content_file" => "$dir_kmz/$routeFile.kmz");
my $ucontent = "";
 
open FILE, encode $encAnsi, "$dir_kmz/$routeFile\.kml" or die $!;
my $zip = Archive::Zip->new();
while (<FILE>) { $ucontent .= $_; }
 
close FILE;
my $status = $zip->read("$dir_kmz/$routeFile.kmz");
my $content = decode $encoding, $ucontent;
 
if ($status != AZ_OK) {
if ($content =~ /<\/tessellate>\s*<coordinates>\s*(.*?)\s*<\/coordinates>/s) {
 
die "Error while reading KMZ file! $!";
my $track = $1;
 
} else {
if ($track =~ /\n/) {
 
my @members = $zip->memberNames();
die "Error: Linebreak within Track\n";
 
}
if ($#members != 0) { die "Error: More than one File within kmz!\n"; }
 
print encode $encOut, "    Saving $routeFile.txt\n";
print encode $encOut, "    Renaming $members[0] -> $routeFile.kml\n";
 
open FILE, ">$dir_kmz/$routeFile\.txt" or die $!;
$zip->extractTree(undef, "$dir_kmz/");
print FILE $track;
 
close FILE;
rename("$dir_kmz/$members[0]","$dir_kmz/$routeFile.kml") || die "Error while Renaming File: $!";
 
} else {
if ($members[0] ne "doc.kml") {
 
print "  Error: No Match in $routeName\n";
if ($members[0] ne "$routeFile.kml") {
die;
 
}
print "WARNING: $routeFile.kml -> $members[0]\n";
}  
}
}
}
 
if ($updateRoutes and $touch) {
my $ucontent = "";
open FILE, encode $encAnsi, "$dir_kmz/$routeFile\.kml" or die $!;
#========================================================
while (<FILE>) { $ucontent .= $_; }
# Update local Routefiles from Wiki if touch-Flag is set
close FILE;
my $content = decode $encoding, $ucontent;
printf "%3d: Trying to update %s\n", $i+1, $routeOut;
 
if ($content =~ /<\/tessellate>\s*<coordinates>\s*(.*?)\s*<\/coordinates>/s) {
$mech->get("http://www.radreise-wiki.de/$routeURL");
 
my $website = $mech->content;
my $track = $1;
 
# Gehe zum Editieren der Route
if ($track =~ /\n/) {
$mech->follow_link( url => "/index.php?title=$routeURL&action=edit" );
 
$website = $mech->content;
die "Error: Linebreak within Track\n";
}
$website =~ /<textarea.*>(.*)<\/textarea>/s;
print encode $encOut, "    Saving $routeFile.txt\n";
my $wikiText = $1;
 
open FILE, ">$dir_kmz/$routeFile\.txt" or die $!;
$wikiText =~ s/&lt;/</g;
print FILE $track;
$wikiText =~ s/&gt;/>/g;
close FILE;
$wikiText =~ s/&quot;/\"/g;
 
$wikiText =~ s/&amp;/\&/g;
} else {
 
if (length $wikiText > 1) {
print "  Error: No Match in $routeName\n";
die;
&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 ($updateRoutes and $touch) {
if (!$result) {
 
print "  No changes in KML-File\n\n";
#========================================================
} else {
# Update local Routefiles from Wiki if touch-Flag is set
print "\n";
 
}
print "Trying to update $routeOut\n";
 
} else {
$mech->get("http://www.radreise-wiki.de/index.php?title=$routeURL&action=edit");
 
die "URL not found: $routeURL\n";
my $website = $mech->content;
}
 
}
$website =~ /<textarea.*?>(.*)<\/textarea>/s;
 
my $newContent;
my $wikiText = $1;
 
if ($modify) {
$wikiText =~ s/&lt;/</g;
$wikiText =~ s/&gt;/>/g;
#=====================================================
$wikiText =~ s/&quot;/\"/g;
# Modify Routefile and save it to different directory
$wikiText =~ s/&amp;/\&/g;
 
my $ucontent = "";
if (length $wikiText > 1) {
open FILE, encode $encAnsi, "$dir_txt/$routeName\.txt" or die $!;
 
while (<FILE>) { $ucontent .= $_; }
&saveFileIfChangedOrNew ("$dir_txt/", "$routeFile.txt", encode $encoding, $wikiText, 0);
close FILE;
 
my $content = decode $encoding, $ucontent;
# External Call. Exit Code : 0 - No Change, 1 - KML-File Changed
my $result = system("perl makeKML.pl $routeFile");
my $match_1 = "";
 
if (!$result) {
if ($content =~ /(Höhenmeter \(ab\) = [ 0-9\.]*\n)\}\}\n/) {
print "  No changes in KML-File\n\n";
} else {
$match_1 = $1;
print "\n";
}
} else {
 
} else {
print "  Error: No Match in $routeName\n";
 
die;
die "URL not found or Edit-Window is empty: >$routeURL<\n";
}
}
}
my $match_2 = "";
 
my $gegenrichtung = "Bild:Ohne Gegenrichtung.png";
my $newContent;
 
if ($content =~ /(\n\{\{[RetT]+our\|[^\}].*\}\}\n)/) {
if ($modify) {
 
$match_2 = $1;
#=====================================================
# Modify Routefile and save it to upload-directory
if ($match_2 =~ /\n\{\{[RetT]+our\|([^\}].*)\}\}\n/) {
 
my $ucontent = "";
$gegenrichtung = $1;
open FILE, encode $encAnsi, "$dir_txt/$routeName\.txt" or die $!;
while (<FILE>) { $ucontent .= $_; }
} else {
close FILE;
my $content = decode $encoding, $ucontent;
print "  Error: No Match in $routeName\n";
 
die;
my $match_1 = "";
}
 
}
if ($content =~ /(Höhenmeter \(ab\) = [ 0-9\.]*\n)\}\}\n/) {
my $replace_1 = "$match_1\| Tour-/Retour-Link = $gegenrichtung\n";
$match_1 = $1;
$replace_1 =~ s/  / /;
 
$replace_1 =~ s/Höhenmeter/Höhenmexer/;
} else {
 
if ($content =~ s/\Q$match_1/$replace_1/) {
print "  Error: No Match in $routeName\n";
die;
} else {
}
print "No Match\n";
 
die;
my $match_2 = "";
}
my $gegenrichtung = "Bild:Ohne Gegenrichtung.png";
 
$content =~ s/\Q$match_2//;
if ($content =~ /(\n\{\{[RetT]+our\|[^\}].*\}\}\n)/) {
$content =~ s/ \n/\n/g;
$match_2 = $1;
$content =~ s/ \n/\n/g;
 
$content =~ s/ \n/\n/g;
if ($match_2 =~ /\n\{\{[RetT]+our\|([^\}].*)\}\}\n/) {
$content =~ s/Höhenmexer/Höhenmeter/;
 
$gegenrichtung = $1;
$newContent = $content;
 
} else {
#print encode 'cp850', "  Saving $routeName\n";
 
print "  Error: No Match in $routeName\n";
open  FOUT, encode $encAnsi, "> $savePath/$routeName.txt" or die $!;
die;
print FOUT encode ($encoding, $newContent);
}
close FOUT;
}
}
 
my $replace_1 = "$match_1\| Tour-/Retour-Link = $gegenrichtung\n";
if ($upload) {
$replace_1 =~ s/  / /;
$replace_1 =~ s/Höhenmeter/Höhenmexer/;
#==========================================
 
# UPLOAD CHANGED TEXTFILES TO THE WIKI !!!
if ($content =~ s/\Q$match_1/$replace_1/) {
 
print encode ('cp850', "  Uploading $routeName to $routeURL\n");
} else {
print "No Match\n";
$mech->get("http://www.radreise-wiki.de/$routeURL");
die;
}
$mech->follow_link( url => "/index.php?title=$routeURL&action=edit" );
 
$content =~ s/\Q$match_2//;
$mech->field( 'wpTextbox1', $newContent);
 
$mech->field( 'wpSummary' , "Test Wiki-Bot: Infobox Tour-/Retour-Link hinzugefügt" );
$content =~ s/ \n/\n/g;
$mech->submit;
$content =~ s/ \n/\n/g;
}
$content =~ s/ \n/\n/g;
}
$content =~ s/Höhenmexer/Höhenmeter/;
 
if ($changesTxt) {
$newContent = $content;
exit(1);
 
} else {
#print encode $encOut, "  Saving $routeName\n";
exit(0);
 
}
open  FOUT, encode $encAnsi, "> $savePath/$routeName.txt" or die $!;
</nowiki>
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);
}
</nowiki>
 
[[Kategorie: Verwaltungs-Software]]

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);
}