Tech Is Hard

Credibility = Talent x Years of experience + Proven hardcore accomplishment

REBOL interface to GnuCash: Uncompressing the data

I first saw REBOL in about 1999 and immediately thought it was about the bitchinest thing since function pointers let me implement polymorphism in C (and assembler).  I am going to try once again, now that I have some free time, to learn it.  As part of a much bigger idea, I want to work with GnuCash files.

GnuCash (I am using version 2.4.8) puts all its data in a compressed file.  I used 7-Zip to check it out and that’s what I’ll use to uncompress it, since I couldn’t get the native REBOL scripts I found to work — but that’s OK, because I can call 7-Zip’s command line version from REBOL.

(Check out how to install on your machine on the REBOL site, please.)

And especially, before I start, I have frankly struggled with this language in the past.  I’ve read that REBOL can be harder to learn if you have a lot of traditional programming experience.

The script should let me select the GnuCash compressed data file to be used as 7-zip’s input and show me the uncompressed data.

Request input file

Ask for GnuCash input file to uncompress

rebol [
    Title: "Process GnuCash data file"
    File: "%rebcash.r"
    Date: 01 Dec 2012
    Purpose: {
        interface to gnucash data

if gc-source-file:
    "Select GnuCash File" "OK" "*.gc" [
    call/console reform [ 
        "C:\Program Files\7-Zip\7z.exe" 'e '-tgzip '-so '-y
            rejoin [ {"} to-local-file clean-path gc-source-file {"} ]

The -so option sends output to stdout.

The /console refinement on call lets me see its output in the REBOL interpreter.

The REBOL rejoin function evaluates the terms in the block and returns a concatenated string of results.  Some magic file system functions are used to turn the REBOL file! type that was returned by request-file into a path the host can be happy with.

So for a simple scripting language, that’s great. Here’s what starts dumping to my screen:

Output from 7-zip

Output in console window

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: