Skip to content

Instantly share code, notes, and snippets.

@tomatrow
Last active June 8, 2018 03:24
Show Gist options
  • Select an option

  • Save tomatrow/0afb00d35794fbe92d5a6e875c673ee9 to your computer and use it in GitHub Desktop.

Select an option

Save tomatrow/0afb00d35794fbe92d5a6e875c673ee9 to your computer and use it in GitHub Desktop.

Revisions

  1. tomatrow revised this gist Jun 8, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    statements
  2. tomatrow revised this gist Jun 4, 2018. No changes.
  3. tomatrow revised this gist Jun 4, 2018. 1 changed file with 35 additions and 31 deletions.
    66 changes: 35 additions & 31 deletions calcoast_extraction.fish
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,53 @@
    #! /usr/local/bin/fish

    set data (cat statements.html)

    echo $data | pup -c "tr:nth-of-type(5)"
    function main

    set i 5
    while set res (echo $data | pup "tr:nth-of-type($i)")
    and [ "$res" != '' ]
    set data (cat statements.html)
    # echo $data | pup -c "tr:nth-of-type(5)"

    ###### Read in data
    set i 5
    while set res (echo $data | pup "tr:nth-of-type($i)")
    and [ "$res" != '' ]

    # I need to `tr:nth-of-type($i)`, else direct children's tags are removed.
    ###### Read in data

    echo $data | pup -p "tr:nth-of-type($i) > td:first-of-type text{}" \
    | string trim | read transDate
    # I need to `tr:nth-of-type($i)`, else direct children's tags are removed.

    echo -n $data | pup -p "tr:nth-of-type($i) > td:nth-of-type(2) > b text{}" \
    | string trim | read transDescription
    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) > div > div:first-of-type text{}" \
    | string trim | read -z transMemo
    echo -n $data | pup -p "tr:nth-of-type($i) > td:nth-of-type(2) > b text{}" \
    | string trim | read transDescription

    # 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:nth-of-type(2) > div > div:first-of-type text{}" \
    | string trim | read -z transMemo

    echo -n $data | pup -p "tr:nth-of-type($i) > td:last-of-type text{}" \
    | string trim -c ' \$' | read transBalance
    # 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
    ##### Transform

    ##### Display
    # (1) convert date format
    strptime -i '%m/%d/%Y' -f '%Y/%m/%d' "$transDate" | read transDate

    # (1) date description
    echo "$transDate $transDescription ; # $transBalance\n \$$transAmount"
    # (2)
    ##### Display

    set i (math "$i + 1")
    end | while read line

    echo $line
    end
    # (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
  4. tomatrow created this gist Jun 4, 2018.
    49 changes: 49 additions & 0 deletions calcoast_extraction.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #! /usr/local/bin/fish

    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"
    # (2)

    set i (math "$i + 1")
    end | while read line

    echo $line
    end