Hi all, long time no post so i thought i'd send this in - it's not hugely clever or difficult, but works well and is IMHO a CUFP.
At work our canteen puts up the menu in doc format which obviously isn't ideal (especially for all the engineers working on bsd).
Below is a solution:
I got them to mail the menu to me attached to a mail
i have a procmail rule thus:
:0:menu.lock
* ^Subject:.*(.*LUNCH MENU)
| menu/menu.pl
which runs it through this script:
#!/usr/bin/perl
# menu.pl a doc menu reformatter
use MIME::Parser;
use Date::Parse;
use POSIX qw(strftime);
my $dir="menu"; # working directory
my $out_dir="htdocs"; # output directory
# use MIME::Parser to output the attachment to MENU.doc
my $parser=new MIME::Parser;
$parser->output_to_core(1);
my $entity=$parser->parse(\*STDIN);
for(@{$entity->{ME_Parts}}){
if($_->{ME_Bodyhandle}->{MB_Binmode}){
open(FH,">$dir/MENU.doc");
print FH join "",@{$_->{ME_Bodyhandle}->{MBC_Data}};
close FH;
last;
}
}
exit if !-e "$dir/MENU.doc"; # exit if no menu found.
# shell out to wvText to convert doc to txt.
system("/usr/local/bin/wvText $dir/MENU.doc $dir/menu.txt") || die;
# what day's lunch is it?
my $date;
for(@{$entity->{mail_inet_head}->{mail_hdr_list}}){
if(/^Date: (.*?\d{4}).*$/){
$date=strftime"%A %B %d %Y",localtime(str2time($1));
last;
}
};
# start of html
$menu=<<EOM;
<html><head><title>Canteen Menu</title><meta http-equiv=\"pragma\" con
+tent=\"no-cache\"></head><body>
<b><u>Menu for $date</u></b><br>
EOM
# read the translated file
open(MENU,"$dir/menu.txt");
while(<MENU>){
# convert to unix format and tidy
s#\cM##gs;
s#^\s+##gs;
chomp;
next if !$_;
# underline headings (sandwiches/soup/main dishes etc).
s#.*(?:sandwiches|soup(?: of the day|:)|(?:main (?:dish(?:es)? (?!pri
+ces))|event)|salads|toasties|desserts|naughties).*#<br><b><u>$&</u></
+b>#is;
# add it to the menu
$menu.= "$_<br>$/";
}
close MENU;
# close html
$menu.="</body></html>";
# put prices after the dish rather than on next line
#(in uk so price in £'s)
$menu=~s#<br>\n£# - £#sg;
my $menu_file="$out_dir/menu.html";
# print output
open(FH,">$menu_file"),
print FH $menu;
close FH;
chmod 0644,$menu_file;
# clean up temporary files made by or used by wvText
unlink "$dir/MENU.doc";
unlink "$dir/menu.txt";
system("/bin/rm /tmp/wv* 2>/dev/null");
Alex