-
Notifications
You must be signed in to change notification settings - Fork 13
/
mail_report
executable file
·110 lines (88 loc) · 3.13 KB
/
mail_report
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
108
109
110
#!/usr/bin/env bash
# Generates weekly PVP reports for Destiny 2, and emails them
#
# Created by Mike Chambers
# https://www.mikechambers.com
#
# Released under an MIT License
# More info at:
# https://github.com/mikechambers/dcli/
#
# This is a pretty simple script / output.
# Requires dcliah v0.8.0
# (pulling from environment but you can also hardcode)
EMAIL_ADDRESS=$EMAIL
# you can get member_id and platform from dclim
# (here it pulls from environment but you can also hardcode)
MEMBER_ID=$MEMBER_ID
PLATFORM=$PLATFORM
# modes to generate a report for. options include: all, control,
# clash, mayhem, ironbanner, private, rumble, comp, quickplay
# and trialsofosiris
declare -a MODES=("all_pvp" "quickplay" "iron_banner" "trials_of_osiris" "rumble" "pvp_competitive" )
REPORT_START=$(date +"%A, %B %-d, %Y")
REPORT_END=$(date +"%A, %B %-d, %Y")
SUBJECT="Destiny Crucible Report for week of ${REPORT_START}"
OUTPUT="Here is your weekly Destiny 2 Crucible report for the week ending on ${REPORT_END}."
OUTPUT+="\n"
OUTPUT+="\n"
echo "Gathering data for report"
# Iterate the string array using for loop
for mode in "${MODES[@]}"; do
echo "Getting data for $mode"
PRETTY_MODE=""
if [ "${mode}" == "all_pvp" ]
then
PRETTY_MODE="All Matches"
elif [ "${mode}" == "quickplay" ]
then
PRETTY_MODE="Quickplay"
elif [ "${mode}" == "iron_banner" ]
then
PRETTY_MODE="Iron Banner"
elif [ "${mode}" == "trials_of_osiris" ]
then
PRETTY_MODE="Trials of Osiris"
elif [ "${mode}" == "rumble" ]
then
PRETTY_MODE="Rumble"
elif [ "${mode}" == "pvp_competitive" ]
then
PRETTY_MODE="Competitive"
fi
OUTPUT+=" ${PRETTY_MODE}\n"
OUTPUT+="************************************************************************************************************\n"
#2>&1 this redirects stderr to stdout so we can capture
TMP_OUTPUT=$(dcliah --member-id "$MEMBER_ID" --platform "$PLATFORM" --class all --mode "$mode" --moment week --activity-limit 0 --weapon-count 10 2> /dev/null)
if [ $? -eq 1 ]
then
echo "${TMP_OUTPUT}">&2 #redirect to stderr
echo -e "\nError running dcliah (see output above). Aborting. Exit code received from command [$?]">&2 #redirect to stderr
exit 1
fi
if [ "${TMP_OUTPUT}" == "No activities found" ]
then
OUTPUT+="No games played"
OUTPUT+="\n"
OUTPUT+="\n"
else
OUTPUT+="${TMP_OUTPUT}"
OUTPUT+="\n"
OUTPUT+="\n"
OUTPUT+="\n"
fi
sleep 2
done
OUTPUT+="\n\n"
OUTPUT+="Report generated using dcli\n"
OUTPUT+="https://github.com/mikechambers/dcli"
#echo -e # | mail -s "${SUBJECT}" $EMAIL_ADDRESS
echo -e "${OUTPUT}\n"
echo "Emailing report to: ${EMAIL_ADDRESS}"
#just wrap in <pre>, so it maintains formatting from dcliah output
BODY="Mime-Version: 1.0\nContent-Type: text/html\n<html><body><pre style=\"font-family: monospace; font-size:medium;\">${OUTPUT}</pre></body></html>"
(echo "To: ${EMAIL_ADDRESS}"
echo "Subject: ${SUBJECT}"
echo "Content-Type: text/html"
echo -e "${BODY}"
) | sendmail -t