Difference between revisions of "Yi-bot.pl"

From Organic Design wiki
(code used to fix hexagram articles)
 
m
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{lowercase}}{{legacy}}
 +
<source lang="perl">
 
#!/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
 +
#
  
 +
# Set up a user agent
 
use HTTP::Request;
 
use HTTP::Request;
 
use LWP::UserAgent;
 
use LWP::UserAgent;
Line 12: Line 16:
 
         );
 
         );
  
 +
# 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';
  
for $i (1..64) {
+
# Your list of article titles
$hex = "Hexagram_$i";
+
@articles = ('foo','bar');
print "$hex\n";
+
 +
# Loop through the article titles
 +
for $title (@articles) {
 +
print "$title\n";
  
$response = $client->get("$wiki?title=$hex&action=raw");
+
# 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;
 
$_ = $response->content;
  
s/<td align/<foo/g;
+
# If your adjusting existing articles, adjust the content here
s/(<td.+?<)/$1\/td></g;
+
s/old/new/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
 
%form = (
 
%form = (
title  => $hex,
+
title  => $title,
 
caction => 'replace',
 
caction => 'replace',
 
summary => $summary,
 
summary => $summary,
content => "$_\n__NOEDITSECTION__"
+
content => $_
 
);
 
);
 
$client->post($wiki,\%form);
 
$client->post($wiki,\%form);
Line 38: Line 45:
 
sleep(0.5);
 
sleep(0.5);
 
}
 
}
 +
</source>
 +
[[Category:PERL]][[Category:Robots]]

Latest revision as of 03:23, 23 April 2020

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.
#!/usr/bin/perl
# Script to create or adjust many articles
#

# 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 = 'Yi-bot script';

# Your list of article titles
@articles = ('foo','bar');
		
# Loop through the article titles
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 => $_
		);
	$client->post($wiki,\%form);

	sleep(0.5);
	}