-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreminder.pl
More file actions
executable file
·108 lines (79 loc) · 1.92 KB
/
reminder.pl
File metadata and controls
executable file
·108 lines (79 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /usr/bin/perl
# $Header:$
use strict;
use warnings;
use File::Basename;
use FileHandle;
use Getopt::Long;
use IO::File;
use POSIX;
#######################################################################
# Command line switches. #
#######################################################################
my %opts;
sub main
{
Getopt::Long::Configure('require_order');
Getopt::Long::Configure('no_ignore_case');
usage() unless GetOptions(\%opts,
'help',
);
usage(0) if $opts{help};
my $fn = shift @ARGV;
usage() if !$fn;
my $fh = new FileHandle($fn);
if (!$fh) {
print "reminder.pl: Cannot open $fn - $!\n";
exit(0);
}
my @lst;
my $d = strftime("%a", localtime());
my $t = strftime("%H%M", localtime());
while (<$fh>) {
next if /^#/;
chomp;
my ($cdate, $enabled, $dow, $times, $interval, $algo, $msg) = split(/,/);
next if ($enabled || '') ne 'enabled';
$dow = "sat sun" if $dow eq 'weekend';
$dow = "mon tue wed thu fri" if $dow eq 'weekday';
$dow = "sat sun mon tue wed thu fri" if $dow eq 'everyday';
next if $dow !~ /$d/i;
if ($times) {
my ($s, $e) = split("-", $times);
next if $t < $s;
next if $e && $t > $e;
}
next if $algo ne 'normal';
push @lst, $msg;
}
my $msg = $lst[rand(@lst)];
exit(0) if !$msg;
if (int(rand(3)) == 0) {
system("figlet " . encode_msg($msg));
} else {
system("toilet -t --gay " . encode_msg($msg));
}
}
sub encode_msg
{ my $m = shift;
return "'$m'" if $m !~ /[']/;
$m =~ s/'/\\'/g;
return $m;
}
#######################################################################
# Print out command line usage. #
#######################################################################
sub usage
{ my $ret = shift;
my $msg = shift;
print $msg if $msg;
print <<EOF;
reminder.pl - simple reminder tool
Usage: reminder.pl <filename>
Randomly print a reminder for today.
Switches:
EOF
exit(defined($ret) ? $ret : 1);
}
main();
0;