forked from DarwinAwardWinner/ofxtoolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-new-ofx.sh
executable file
·66 lines (53 loc) · 1.5 KB
/
import-new-ofx.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
#!/bin/bash
# Directories
OFX_DIR="$HOME/Documents/finance"
NEW_DIR=".new"
OLD_DIR=".old"
# Programs
# fixofx.py from wesabe
FIXOFX="/home/ryan/src/wesabe/fixofx/fixofx.py"
MUNGEOFX="/home/ryan/Projects/ofxtoolkit/mungeofx.pl"
MERGEOFX="/home/ryan/Projects/ofxtoolkit/mergeofx-simple.pl"
RENAMEOFX="/home/ryan/Projects/ofxtoolkit/renameofx.pl"
shopt -s nullglob
mkdir -p "$OFX_DIR"
{
cd "$OFX_DIR"
mkdir -p "$NEW_DIR" "$OLD_DIR"
# Clean stale temp files
rm -f "$OLD_DIR"/TEMPOFX.*
#tempfiles=""
# Fix OFX files, move them from old to new, and rename them
{
cd "$NEW_DIR"
if [ "`echo *.ofx *.qfx`" != "" ]; then
echo "Fixing..."
for x in *.ofx *.qfx; do
tempfile=`mktemp -p "../${OLD_DIR}" -t TEMPOFX.XXXXXXXXX`
cat "$x" | perl -lape 's/<DTASOF \/>//g' | "$FIXOFX" > "$tempfile" || { echo "fixofx failed on $x"; exit 1; }
done
else
echo "No new files to import."
fi
cd ..
}
# Munge and merge OFX files
{
cd "$OLD_DIR"
if [ "`echo TEMPOFX.*`" != "" ]; then
echo "Munging..."
"$MUNGEOFX" TEMPOFX.* || { echo "Munging failed"; exit 1; }
echo "Merging..."
else
echo "Updating existing files..."
fi
"$MERGEOFX" --output-directory "$OFX_DIR" --update TEMPOFX.* || { echo "Merge failed"; exit 1; }
if [ "`echo TEMPOFX.*`" != "" ]; then
echo "Renaming..."
"$RENAMEOFX" TEMPOFX.* || { echo "renameofx failed"; exit 1; }
trash ../"$NEW_DIR"/*.[oq]fx
fi
cd ..
}
}
echo "Done."