Kategorien
Benutzer:Count Ypsilon/Skript:maplist.pl
Zur Navigation springen
Zur Suche springen
Skript zur Erzeugung einer einfachen, kommaseparierten Liste aller Felder.
Spalte 1=Gebietsname, Spalten 2/3=x und y, Spalte 4=NPC-Name (Feld ist mehrfach in Liste, wenn mehrere NPCs, und einfach mit "none" in Spalte 4, wenn kein NPC)
#!/usr/bin/perl use strict; use LWP::UserAgent; use URI::Escape; use HTTP::Request; my $ua = LWP::UserAgent->new(); my $host = "http://www.fwwiki.de"; my $url = $host . "/index.php/Kategorie:Karten"; while($url ne "") { #print "GET $url\n"; my $request = HTTP::Request->new("GET", $url); my $response = $ua->simple_request($request); my $c = $response->content(); $url = ""; while($c =~ /<a([^>]*)>([^<]*)<\/a>/gm) { my ($anchor, $text) = ($1, $2); my $href; $href = $1 if ($anchor =~ /href\s*=\s*"([^"]*)"/); $href =~ s/&/&/g; my $title; $title = $1 if ($anchor =~ /title\s*=\s*"([^"]*)"/); $url = $host.$href if ($text =~ /n.*chste \d+/); fetchMap($1, $host.$href) if ($text =~ /Karte:\s*(.*)/); } } sub fetchMap { my ($text, $href) = @_; my $request = HTTP::Request->new("GET", $href."?action=edit"); my $response = $ua->simple_request($request); my $c = $response->content(); my @lines = split(/\n/, $c); my $firstx; my $curx; my $cury; my $opened; my $firstline = 1; foreach my $line(@lines) { next unless ($line =~ /\{\{Karte\/([^|{}\/]+)(\/([^|{}]+))?(\|([^{}]*))?\}\}(\{\{.*\}\})?/); my ($vorlage, $sub, $argl, $more) = ($1, $3, $5, $6); my @args = split(/\|/, $argl); if (!$opened) { $opened = 1 if ($vorlage eq "Beginn"); next; } if ($vorlage eq "Ende") { last; } elsif ($vorlage eq "NeueZeile") { $firstline = 0; $curx = $firstx; } elsif ($vorlage eq "Koord") { if (($firstline) && (!defined($firstx))) { $firstx = $args[0]; } else { $cury = $args[0]; } } elsif ($vorlage =~ /^Feld\d*$/) { shift(@args); foreach my $npc(@args) { print "$text,$curx,$cury,$npc\n"; } $curx++; } else { print "unbekannt: $vorlage\n" unless ($vorlage =~ /^(Berg|Leer|Grenzfeld)$/); $curx++; } } } print <<EOF; Lardikia,126,114,Stegovar Lardikia,127,114,Goldkrake EOF