User:Cyde/Featured pictures/Source

From Wikipedia, the free encyclopedia

GPL

This work is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.

This work is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Usage is as follows:

./wikipics.pl > output.txt

Then just go ahead and copy the contents of output.txt directly into the Edit Box on Wikipedia.

Current version is 0.4

#!/usr/bin/perl
#You will need libwww-perl, available at:
#http://search.cpan.org/~gaas/libwww-perl-5.805/

require LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(10);

#We need to spoof the user agent or Wikipedia will block us :-O
$ua->agent('Mozilla/5.0');

my $response = $ua->get("http://en.wikipedia.org/w/index.php?title=Wikipedia:Featured_pictures&action=raw&ctype=text/css");

if (!$response->is_success) {
    die $response->status_line;
}

print "Here is a list of all Featured Pictures as of " . localtime() . ".  This was generated by a simple \[\[Perl\]\] script that I ran on the Wiki source of the \[\[Wikipedia:Featured pictures\]\] page.  The Perl script's source is available \[\[User:Cyde/Featured pictures/Source | here\]\].\n\n";

print "\'\'Warning\'\' - If you have a slow computer or a slow connection trying to load this page will make your computer choke.\n\n";

my $galleryOpen = 0;

foreach (split /\n/, $response->content) {
    if ($_ =~ /\[\[\:(Image\:.*\.(?:jpg|gif|png))\|.*\]\]/i) {
        print $1 . "\n";
    }
    elsif ($_ =~ /^\s*(===*.*===*)\s*$/) {
        my $temp = $1;
        if ($temp =~ /^==[^=]*==$/) {
            print "$temp\n";
        }
        else {
            if ($galleryOpen == 1) {
                print "</gallery>\n";
                $galleryOpen = 0;
            }
            print "$temp\n";
            print "<gallery>\n";
            $galleryOpen = 1;
        }
    }
}

print "</gallery>\n" if ($galleryOpen);

This program is licensed under the GPL as follows:

Copyright (C) 2005–2006 Ben "Cyde" McIlwain

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.