-
Notifications
You must be signed in to change notification settings - Fork 0
/
chessgames-dotcom
90 lines (61 loc) · 1.63 KB
/
chessgames-dotcom
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
#!/usr/bin/perl
# The PGN archive files must exist even if zero-length for this
# program to prepend to them.
use strict;
use Chess::Games::DotCom;
use Data::Dumper;
use File::Butler;
#use File::Temp qw/ tempfile / ;
use Log::Agent;
use Log::Agent::Driver::File;
use Log::Agent::Priorities qw(:LEVELS);
$Log::Agent::Debug=10;
logconfig(-driver =>
Log::Agent::Driver::File->make(
-prefix => $0,
-showpid => 1,
-channels => {
'error' => "$0.err",
'output' => "$0.out",
'debug' => "$0.dbg",
},
)
);
# Where the PGN files for game of day and puzzle of day are kept
my $PGN_DIR = "$ENV{HOME}/chess";
# Don't touch %sub :)
my %sub =
(
pod => 'puzzle_of_day',
god => 'game_of_day'
);
# The names of the PGN files to prepend to as a function of the input
# command-line parameter
my %perm_file = map {
($_ => "$PGN_DIR/$sub{$_}.pgn")
} (keys %sub);
logdbg NOTICE, "pgn output files: " . Dumper(\%perm_file);
# Start of Code
sub usage {
<<EOUSAGE
This script returns the
Game of Day (god) or
Puzzle of Day (pod)
USAGE:
$0 (pod|god)
EOUSAGE
}
my $podgod = shift or logdie usage;
$podgod =~ /^(p|g)od$/ or logdbg NOTICE, usage;
#my ($fh, $tempfile) = tempfile ( $podgod . "XXXX" , SUFFIX => '.pgn' );
#close $fh;
my $tempfile = 'tempfile.pgn';
no strict 'refs';
my $SUB = $sub{$podgod};
$SUB->($tempfile);
# Create the perm file name
my $perm_file = $perm_file{$podgod};
logdbg 'notice:4', "WRITING $perm_file FROM $tempfile";
open T, $tempfile or die $!;
my @T = <T>;
Butler($perm_file, 'prepend', \@T) or logdie $!;