Difference between revisions of "Yi-bot.pl"
m |
(comments) |
||
Line 2: | Line 2: | ||
# Script to fix up hexagram articles which used "casual HTML" for their tables which MW 1.9.x doesn't allow{{perl}}{{Category:Yi}} | # Script to fix up hexagram articles which used "casual HTML" for their tables which MW 1.9.x doesn't allow{{perl}}{{Category:Yi}} | ||
+ | # Set up a user agent | ||
use HTTP::Request; | use HTTP::Request; | ||
use LWP::UserAgent; | use LWP::UserAgent; | ||
Line 12: | Line 13: | ||
); | ); | ||
+ | # Wiki script URL and comment to use for edit summary | ||
$wiki = 'http://www.organicdesign.co.nz/wiki/index.php'; | $wiki = 'http://www.organicdesign.co.nz/wiki/index.php'; | ||
$summary = 'Convert table syntax to non-casual HTML'; | $summary = 'Convert table syntax to non-casual HTML'; | ||
+ | # Loop through the 64 hexagrams | ||
for $i (1..64) { | for $i (1..64) { | ||
$hex = "Hexagram_$i"; | $hex = "Hexagram_$i"; | ||
print "$hex\n"; | print "$hex\n"; | ||
+ | # Read the raw wikitext of the current hexagram | ||
$response = $client->get("$wiki?title=$hex&action=raw"); | $response = $client->get("$wiki?title=$hex&action=raw"); | ||
$_ = $response->content; | $_ = $response->content; | ||
+ | # Fix the article with regular expression replacements | ||
s/<td align/<foo/g; | s/<td align/<foo/g; | ||
s/(<td.+?<)/$1\/td></g; | s/(<td.+?<)/$1\/td></g; | ||
Line 28: | Line 33: | ||
s/<foo/<\/td><td align/g; | s/<foo/<\/td><td align/g; | ||
+ | # Update the article by posting a form using a Simple Forms request | ||
%form = ( | %form = ( | ||
title => $hex, | title => $hex, |
Revision as of 11:05, 1 September 2007
- !/usr/bin/perl
- Script to fix up hexagram articles which used "casual HTML" for their tables which MW 1.9.x doesn't allowOur Perl scripts.
Our Favourite I Ching & Taoist Books
These books are from The Book Depository who deliver anywhere in the world for free!
Quick Hexagram Index
Trigram Overview |
|
- Set up a user agent
use HTTP::Request; use LWP::UserAgent; $client = LWP::UserAgent->new(
cookie_jar => {}, agent => 'Mozilla/5.0', from => 'wikid.pl@organicdesign.co.nz', timeout => 10, max_size => 100000 );
- Wiki script URL and comment to use for edit summary
$wiki = 'http://www.organicdesign.co.nz/wiki/index.php'; $summary = 'Convert table syntax to non-casual HTML';
- Loop through the 64 hexagrams
for $i (1..64) { $hex = "Hexagram_$i"; print "$hex\n";
# Read the raw wikitext of the current hexagram $response = $client->get("$wiki?title=$hex&action=raw"); $_ = $response->content;
# Fix the article with regular expression replacements s/<td align/<foo/g; s/(<td.+?<)/$1\/td></g; s/(<tr.+?)(?=<tr)/$1<\/tr>/g; s/<\/table><\/table>/<\/tr><\/table><\/td><\/tr><\/table>/g;
s/<foo/<\/td> $hex,
caction => 'replace', summary => $summary, content => "$_\n" ); $client->post($wiki,\%form);
sleep(0.5); }