fixstmt

Tool to rename bank statements to yyyy-mm-dd format
git clone https://git.bracken.jp/fixstmt.git
Log | Files | Refs | LICENSE

commit 507afed27c8ee0cf901cbd8d17c62dffc498104d
Author: Chris Bracken <chris@bracken.jp>
Date:   Sat, 28 Aug 2021 17:54:32 -0700

Initial commit

Copies fixrbc.go from the tools repository.

Diffstat:
ALICENSE | 26++++++++++++++++++++++++++
Afixrbc.go | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,26 @@ +Copyright 2000, Chris Bracken <chris@bracken.jp> + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/fixrbc.go b/fixrbc.go @@ -0,0 +1,63 @@ +// CLI tool to rename all RBC statement PDFs in the current directory to +// YYYY-MM-DD.pdf format. +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "strings" +) + +func main() { + files, err := ioutil.ReadDir("./") + if err != nil { + log.Fatal(err) + } + for _, f := range files { + if strings.HasSuffix(f.Name(), ".pdf") { + // Format: ACCTNO-YYYYmmmDD-YYYYmmmDD.pdf + date := strings.Split(f.Name(), "-")[2][0:9] + y := date[0:4] + m, err := getMonthNumber(date[4:7]) + if err != nil { + log.Fatal(err) + } + d := date[7:9] + + newFname := fmt.Sprintf("%s-%s-%s.pdf", y, m, d) + os.Rename(f.Name(), newFname) + } + } +} + +func getMonthNumber(m string) (string, error) { + switch { + case m == "Jan": + return "01", nil + case m == "Feb": + return "02", nil + case m == "Mar": + return "03", nil + case m == "Apr": + return "04", nil + case m == "May": + return "05", nil + case m == "Jun": + return "06", nil + case m == "Jul": + return "07", nil + case m == "Aug": + return "08", nil + case m == "Sep": + return "09", nil + case m == "Oct": + return "10", nil + case m == "Nov": + return "11", nil + case m == "Dec": + return "12", nil + } + return "", fmt.Errorf("Bad month name: %s", m) +}