Last active
June 8, 2018 03:24
-
-
Save tomatrow/0afb00d35794fbe92d5a6e875c673ee9 to your computer and use it in GitHub Desktop.
Convert CalCoast statements to something ledger can use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
statements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/fish | |
function main | |
set data (cat statements.html) | |
# echo $data | pup -c "tr:nth-of-type(5)" | |
set i 5 | |
while set res (echo $data | pup "tr:nth-of-type($i)") | |
and [ "$res" != '' ] | |
###### Read in data | |
# I need to `tr:nth-of-type($i)`, else direct children's tags are removed. | |
echo $data | pup -p "tr:nth-of-type($i) > td:first-of-type text{}" \ | |
| string trim | read transDate | |
echo -n $data | pup -p "tr:nth-of-type($i) > td:nth-of-type(2) > b text{}" \ | |
| string trim | read transDescription | |
echo -n $data | pup -p "tr:nth-of-type($i) > td:nth-of-type(2) > div > div:first-of-type text{}" \ | |
| string trim | read -z transMemo | |
# I remove a bunch of whitespace by matching non empty lines | |
echo -n $data | pup -p "tr:nth-of-type($i) > td:nth-last-of-type(2) text{}" \ | |
| string match -r '[^\\s]+' \ | |
| string trim -c ' ()\$' | read transAmount | |
echo -n $data | pup -p "tr:nth-of-type($i) > td:last-of-type text{}" \ | |
| string trim -c ' \$' | read transBalance | |
##### Transform | |
# (1) convert date format | |
strptime -i '%m/%d/%Y' -f '%Y/%m/%d' "$transDate" | read transDate | |
##### Display | |
# (1) date description | |
echo "$transDate $transDescription ; # $transBalance\n \$$transAmount" | |
set i (math "$i + 1") | |
end | |
end | |
set reversed (echo (main)[-1..1]) | |
for line in $reversed | |
echo -e $line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment