Archive
file: potd.pl
1: #!/usr/bin/env perl
2: use 5.010;
3: use strict;
4: use warnings;
5: use Imager;
6: use Path::Class;
7: use File::Copy;
8: use Time::Moment;
9: use File::HomeDir;
10:
11: my $raw = file( $ARGV[0] );
12: die "No such file $ARGV[0]" unless -e $raw;
13:
14: my $day_offset = defined $ARGV[1] ? $ARGV[1] : 1;
15: my $date = Time::Moment->now->plus_days($day_offset);
16: my $basename = $date->strftime("%Y-%m-%d");
17: say "Creating POTD for $basename, ok?";
18: my $ok = <STDIN>;
19:
20: my $home = dir( File::HomeDir->my_home );
21: my $blio = $home->subdir(qw(privat domm.plix.at));
22: my $potd_src = $blio->subdir(qw( src potd ));
23: my $target_img = $potd_src->file( $basename . '.jpg' );
24: my $target_txt = $potd_src->file( $basename . '.txt' );
25: if ( -e $target_img ) {
26: say "target $basename.jpg already exists, aborting";
27: exit;
28: }
29:
30: my $image = Imager->new;
31: $image->read( file => $raw );
32: my $scaled = $image->scale( xpixels => 800 );
33: $scaled->write( file => $target_img );
34:
35: move( $raw,
36: $home->subdir(qw(media fotos 2015 potd))->file( $basename . '.jpg' ) );
37:
38: my $publish_date = $basename . 'T10:00:00';
39: $target_txt->spew(
40: <<EOBLIO
41: title:
42: tweet:
43: date: $publish_date
44: converter: textile
45: template: potd.tt
46:
47: EOBLIO
48: );
49: system("vim $target_txt");
50:
51: chdir( $target_img->parent );
52: system( join( ' ', 'git add ', $target_img, $target_txt ) );
53: system("git commit -m 'potd $basename'");
54: system('git push');
55:
56: chdir($blio);
57: say "starting to build local website";
58: system('./build_t430 --noschedule > /dev/null');
59: say "done building local website";
60: