-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfetch-transactions.sh
executable file
·68 lines (54 loc) · 1.44 KB
/
fetch-transactions.sh
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
#!/bin/bash
cd "$(dirname "$0")"
COOKIEFILE="/tmp/cookie-mint.txt"
USEOLDCOOKIE=true
source config.sh
if [ -z $CSVDIR ]; then
echo "Unable to load config file. Exiting."
exit 1
fi
if [ ! -d $CSVDIR ]; then
echo "CSV directory does not exist. Exiting."
exit 1
fi
CSVFILE="$CSVDIR/$(date +"%Y-%m-%d_%H-%M-%S").csv"
if [ -f $COOKIEFILE ]; then
if ! $USEOLDCOOKIE; then
echo "" > $COOKIEFILE
echo "Cleared cookie file."
fi
else
touch $COOKIEFILE
echo "Created cookie file."
fi
function checkLoggedIn {
URL="https://wwws.mint.com/overview.event"
LINES=`curl -v -b $COOKIEFILE -c $COOKIEFILE $URL 2>&1 | wc -l`
if [ $LINES -gt 75 ]; then
echo "Currently logged in."
ISLOGGEDIN=true
else
echo "Not logged in."
ISLOGGEDIN=false
fi
}
checkLoggedIn
if ! $ISLOGGEDIN; then
echo "Submitting login form..."
URL="https://wwws.mint.com/loginUserSubmit.xevent"
DATA="username=$USERNAME&password=$PASSWORD&task=L"
curl -v -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$DATA" -b $COOKIEFILE -c $COOKIEFILE $URL &>/dev/null
checkLoggedIn
if ! $ISLOGGEDIN; then
echo "Error logging in. Exiting."
exit 1
fi
fi
if [ "$1" = "loginonly" ]; then
echo "Login only flag detected. Exiting."
exit 0
fi
echo "Fetching transactions..."
URL="https://wwws.mint.com/transactionDownload.event"
curl -b $COOKIEFILE -c $COOKIEFILE $URL 2>/dev/null > $CSVFILE
echo "Transactions saved to: $CSVFILE"