From d40d0e602ca17360dc880cc0ffedeae8f0778fba Mon Sep 17 00:00:00 2001 From: lookshe Date: Wed, 7 Mar 2012 12:05:45 +0100 Subject: fucking wiki api sucks very hard... --- wiki2.pl | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/wiki2.pl b/wiki2.pl index c2033ad..1ce94f3 100644 --- a/wiki2.pl +++ b/wiki2.pl @@ -22,18 +22,25 @@ if (defined $result) { my $newline = ""; my $isDis = 0; my $ln = 0; + my $comment = 0; foreach my $line (@lines) { +#print "$line\n"; $line =~ s///g; + $line=~ s/^}}//g; + $line=~ s/^\]\]//g; $line=~ s/^\s*//; $line=~ s/\s*$//; - if ($line && $line =~ m/^\* / && $ln < 3) { + $comment = 1 if $line =~ m/^$/; + if ($line && $line =~ m/^\* /) { push(@newlines, $newline); push(@newlines, $line); $newline = ""; - $isDis = 1; + $isDis = 1 if $ln < 3; } elsif ($line) { $newline = "$newline$line "; $ln++; + } elsif ($comment) { } else { push(@newlines, $newline); $newline = ""; @@ -41,28 +48,31 @@ if (defined $result) { } push(@newlines, $newline); $ln = 0; + my $lst = 0; foreach my $line (@newlines) { - $line=~ s/{{.*}}//g; + $line =~ s///g; + $line=~ s/.*}}//g; $line=~ s/^\s*//; $line=~ s/\s*$//; if ($line !~ m/^\s*$/) { if ($isDis) { if ($line =~ m/^\* /) { + last if $ln == 3; + $lst = 1 if $ln == 2; print "$line\n"; $ln++; - last if $ln == 3; } } else { $line = decode_entities($line); #$line =~ s/\([^\(\)]*\)||\[[^\[\]]*\]//g; - $line =~ s/\[\[([^\]]*)\]\]/$1/g; + $line =~ s/\[\[([^|\]]*\|)?([^\]]*)\]\]/$2/g; $line =~ s/\'([^\']*)\'/$1/g; $line =~ s/\[\s*\]//g; $line =~ s/\(\s*\)//g; $line =~ s/\[\s*\]//g; $line =~ s/\(\s*\)//g; #$line = strip_tags($line); - $line =~ s/[^<]*<\/ref>//g; + $line =~ s/]*>[^<]*<\/ref>//g; $line =~ s/\s+/ /g; $line =~ s/\s([,.\?!])/$1/g; if ($line =~ m/.{448}.*/) { @@ -75,7 +85,7 @@ if (defined $result) { } } } - if ($isDis) { + if ($isDis && $lst) { print "For more see http://$lang.wikipedia.org/wiki/$ARGV[0]\n"; } } else { -- cgit v1.2.3