Difference between revisions of "Yi-bot.pl"

From Organic Design wiki
(comments)
(Make more generic)
Line 1: Line 1:
 
#!/usr/bin/perl
 
#!/usr/bin/perl
# 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 create or adjust many articles{{perl}}
  
 
# Set up a user agent
 
# Set up a user agent
Line 15: Line 15:
 
# Wiki script URL and comment to use for edit summary
 
# 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 = 'Yi-bot script';
  
 +
# Your list of article titles
 +
@articles = ('foo','bar');
 +
 
# Loop through the 64 hexagrams
 
# Loop through the 64 hexagrams
for $i (1..64) {
+
for $title (@articles) {
$hex = "Hexagram_$i";
+
print "$title\n";
print "$hex\n";
 
  
# Read the raw wikitext of the current hexagram
+
# If your adjusting existing articles, read the existing title's wikitext, otherwise read content from a file
$response = $client->get("$wiki?title=$hex&action=raw");
+
$response = $client->get("$wiki?title=$title&action=raw");
 
$_ = $response->content;
 
$_ = $response->content;
  
# Fix the article with regular expression replacements
+
# If your adjusting existing articles, adjust the content here
s/<td align/<foo/g;
+
s/old/new/g;
s/(<td.+?<)/$1\/td></g;
 
s/(<tr.+?)(?=<tr)/$1<\/tr>/g;
 
s/<\/table><\/table>/<\/tr><\/table><\/td><\/tr><\/table>/g;
 
s/<foo/<\/td><td align/g;
 
  
 
# Update the article by posting a form using a Simple Forms request
 
# Update the article by posting a form using a Simple Forms request
 
%form = (
 
%form = (
title  => $hex,
+
title  => $title,
 
caction => 'replace',
 
caction => 'replace',
 
summary => $summary,
 
summary => $summary,

Revision as of 21:05, 19 October 2007

  1. !/usr/bin/perl
  2. Script to create or adjust many articlesOur Perl scripts.
  1. 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
       );
  1. Wiki script URL and comment to use for edit summary

$wiki = 'http://www.organicdesign.co.nz/wiki/index.php'; $summary = 'Yi-bot script';

  1. Your list of article titles

@articles = ('foo','bar');

  1. Loop through the 64 hexagrams

for $title (@articles) { print "$title\n";

# If your adjusting existing articles, read the existing title's wikitext, otherwise read content from a file $response = $client->get("$wiki?title=$title&action=raw"); $_ = $response->content;

# If your adjusting existing articles, adjust the content here s/old/new/g;

# Update the article by posting a form using a Simple Forms request %form = ( title => $title, caction => 'replace', summary => $summary, content => "$_\n" ); $client->post($wiki,\%form);

sleep(0.5); }