LoremTiddlers

nicolaw 28th March 2018 at 2:02pm
Perl TiddlyWiki

This will create 100 dummy tiddler files for you for testing out your TiddlyWiki.

#!/usr/bin/perl -wT

use strict;
use warnings;

use Text::Lorem qw();
use POSIX qw(strftime);

sub lorem {
  my $text = shift;
  my $output = "";
  for (my $i=-1; $i<=rand(6); $i++) {
    $output .= $text->sentences(rand(20)+2)."\n\n";
  }
  return $output;
}

sub main {
  my $text = Text::Lorem->new();
  for (0..1000) {
    my $title = $text->words(1);
    if (open(my $fh, '>', "$title.tid")) {
      print $fh "title: $title\n";
      print $fh "tags: LoremIpsum\n";
      print $fh "type: text/vnd.tiddlywiki\n";
      print $fh strftime("created: %Y%m%d%H%M%S000\n", localtime);
      print $fh strftime("modified: %Y%m%d%H%M%S000\n", localtime);
      print $fh "\n";
      print $fh lorem($text);
      close($fh);
    }
  }
}

&main($@);