-
Notifications
You must be signed in to change notification settings - Fork 3
/
pp-donation.awk
60 lines (48 loc) · 1.18 KB
/
pp-donation.awk
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
# pp-donation.awk -*- awk -*-
#
# Extract donation details from a Paypal notification mail. This is
# called from a shell script because we need to use gawk's -b option.
BEGIN {
FS = ":"
}
FNR==1 && NR > 1 { result() }
/^Donation Details/ { in_details = 1; next }
!in_details && /^[Dd][Aa][Tt][Ee]:/ {
date=trim($2 ":" $3 ":" $4)
if (match(date, /^[a-zA-Z0-9,-: \t]+$/))
{
cmd = "date -d '" date "' +'%F'"
cmd | getline date
close(cmd)
}
else
{
date = "INVALID DATE"
}
}
!in_details && /^This email confirms.*from/ {
email = gensub(/.*\(([^)]+)\)\..*/, "\\1", 1)
}
!in_details { next }
/^[ \t]*Total amount:/ {split($2, a, " "); sub(/,/, ".", a[1]); amount = a[1]}
/^The following.*Publish my sponsor name\?/ {
publish = substr(trim($3), 1, 1)
}
/^Contributor:/ { name = trim($2) }
END {
result()
}
function result() {
printf "| %s | %s | %s | %s | %s |\n", date, amount, publish, name, email
date=""
amount=""
publish=""
name=""
email=""
in_details=0
}
function trim(s) {
sub (/[ \t]+$/, "", s)
sub (/^[ \t]+/, "", s)
return s
}