Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: 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 = " +ogin"; my $wikiuploader = " +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"; } }

In reply to Mechanized uploading of images for wikimediasites by boo_radley

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-09-26 08:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found