-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_daily
executable file
·77 lines (59 loc) · 1.51 KB
/
stats_daily
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
#!/usr/bin/perl
use POSIX qw(strftime);
if ($ARGV[0]=~/^(\d\d\d\d\-\d\d)$/)
{$curr_month=$1}
else {
$curr_month=strftime "%Y-%m", localtime;
}
open IN, "<ambar.txt";
while(<IN>)
{
$i++;
chomp;
#skip whitespace lines
s/\#.*//;
if (/^\s*$/) {next}
if (/^DEFAULT_CURRENCY/) {next}
if (/^(\d{4}-\d\d-\d\d)\s+(\S+)\s+([\d\.]+[\w\$]+)($|\s)/)
{
$date=$1;
$descr=$2;
$sum=$3;
$month=$date;
$month=~s@-\d\d$@@;
#print "date=$date sum=$sum\n";
if ($month ne $curr_month) {next}
if ($sum=~/\$$/)
{
$sum=~s/\$//;
}
else
{
#$sum=ccc($sum,"byr","usd",$date);
print "junk line #$i : $_ \n exit!\n"; exit;
}
$day_hash{$date}+=$sum ;
$day_hash_descr{$date}.=" $descr;" ;
$month_hash{$month}+=$sum ;
}
else
{print "junk line #$i : $_ \n exit!\n"; exit; }
}
# print current month payments
foreach $date (sort keys %day_hash)
{
if ($date=~/^$curr_month/) {
print $date," ",sprintf("%.2f\$", $day_hash{$date}),"\t",$day_hash_descr{$date},"\n";
}
}
print "-"x30,"\n";
print "$curr_month\t",(0+$month_hash{$curr_month}),"\$\n";
sub ccc {
my $amount=shift;
my $from=shift;
my $to=shift;
my $date=shift;
my $ccc=`ccc $amount $from $to $date`;
chomp $ccc;
return $ccc;
}