Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Mechanized uploading of images for wikimediasites

by boo_radley (Parson)
on Aug 15, 2005 at 19:57 UTC ( #483964=CUFP: print w/replies, xml ) Need Help??

I'm experimenting with a wiki at work, and I have a bunch of illustrations and various images that I wanted to automatically have available to me as I was editing. There are enough of them that adding by hand was onerous, and adding via FTP & manual manipulation of the database was equally unappealing. Here is a WWW::Mechanize script that will upload pngs to a wikipedia. Alter lines 5 through 9 to suit your installation of wikimedia
#! perl.exe $|++; use strict; use WWW::Mechanize; my $wikilogin = "http://example.com/wiki/index.php?title=Special:Userl +ogin"; my $wikiuploader = "http://example.com/wiki/index.php?title=Special:Up +load"; my $user = 'username'; my $pass = 'password'; my $description = 'Media uploaded via automation'; # # begin real work here # my $agent = WWW::Mechanize->new(); $agent->get ($wikilogin); my $form = $agent->form_name('userlogin'); $agent->field ('wpName',$user); $agent->field ('wpPassword',$pass); $agent->field ('wpRemember',1); $agent->click (); open (ERRFH, ">errored.txt"); while (<*.png>){ $agent->get($wikiuploader); my $form = $agent->forms(1); if ($form) { #we've found the form, fill it out # fill out the body $agent->field('wpUploadFile', $_); $agent->field('wpUploadDescription', $description); $agent->field('wpUploadAffirm',1);# and submit $agent->click('wpUpload'); print "saved $_\n"; } else { #something's gone wrong #simple log for now #TODO: fill out w/ better logic. print ERRFH "$_\n"; } }

Replies are listed 'Best First'.
Re: Mechanized uploading of images for wikimediasites
by b10m (Vicar) on Aug 15, 2005 at 20:23 UTC
      Perhaps the script can be considered a new example to be looked at as well.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://483964]
Approved by Corion
Front-paged by planetscape
help
Chatterbox?
[Lady_Aleena]: Having to rewrite some parts of my site for mobile devices is such a pain in the butt.
[shmem]: Lady_Aleena: what editor are you using, on what platform?
[Lady_Aleena]: shmem, geany on Debian jessie.
[shmem]: some experience with vim?
[Lady_Aleena]: None
[shmem]: I don't know geany, and don't know whether it has support for ctags.
[Lady_Aleena]: ctags?
[shmem]: ctags is a program which (recursively) extracts the symbols from source and stores them in a one-file database. This allows you to query the locations where these symbols (e.g. a subroutine name) are used anywhere in the source code tree...
[shmem]: ...from inside the editor.
[shmem]: apt-get install exuberant-ctags

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-04-27 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (505 votes). Check out past polls.