summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/README5
-rwxr-xr-xscripts/bal26
-rwxr-xr-xscripts/confirm.py40
-rwxr-xr-xscripts/entry16
-rwxr-xr-xscripts/getquote16
-rwxr-xr-xscripts/mean27
-rwxr-xr-xscripts/profit2
-rwxr-xr-xscripts/reg14
-rwxr-xr-xscripts/report17
-rwxr-xr-xscripts/spending8
-rwxr-xr-xscripts/stripreg16
-rwxr-xr-xscripts/test14
-rwxr-xr-xscripts/version5
-rwxr-xr-xscripts/worth2
14 files changed, 208 insertions, 0 deletions
diff --git a/scripts/README b/scripts/README
new file mode 100644
index 00000000..7221f95f
--- /dev/null
+++ b/scripts/README
@@ -0,0 +1,5 @@
+This scripts are provided just in the way of giving ideas. They
+probably all need to be modified to suit your particular environment.
+Beware!
+
+John
diff --git a/scripts/bal b/scripts/bal
new file mode 100755
index 00000000..a6d97ab9
--- /dev/null
+++ b/scripts/bal
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+switch=""
+current="-c"
+limit="-l \$50"
+
+if [ "$1" = "-C" -o "$1" = "-U" -o "$1" = "-P" ]; then
+ switch="$1"
+ shift
+elif [ "$1" = "-b" -o "$1" = "-e" ]; then
+ current="$1 $2"
+ shift 2
+fi
+
+accts="$@"
+if [ -z "$accts" ]; then
+ accts="-Equity -Income -Expenses"
+ if [ ! "$switch" = "-P" ]; then
+ accts="$accts -Savings -Retirement"
+ fi
+else
+ limit=""
+ negonly=""
+fi
+
+ledger $current $limit $negonly -s $switch balance $accts
diff --git a/scripts/confirm.py b/scripts/confirm.py
new file mode 100755
index 00000000..c3fe70ab
--- /dev/null
+++ b/scripts/confirm.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+# This script confirms what ledger tells you.
+
+import sys
+import os
+import re
+
+def clean(num):
+ return float(re.sub("(\s+|\$|,)","",num))
+
+running_total = 0.0
+index = 1
+last_line = ""
+
+for line in os.popen("./ledger %s reg %s" % (sys.argv[1], sys.argv[2])):
+ value = clean(line[55:67])
+ total = clean(line[68:80])
+
+ running_total += value
+ if abs(running_total - total) > 0.001:
+ print "! discrepancy of %.2f (%.2f - %.2f) at line %d:" % \
+ (running_total - total, running_total, total, index)
+ print line,
+ running_total = total
+
+ index += 1
+ last_line = line
+
+balance_total = 0.0
+
+for line in os.popen("./ledger %s bal %s" % (sys.argv[1], sys.argv[2])):
+ balance_total = clean(line[:20])
+
+if abs(balance_total - running_total) > 0.001:
+ print
+ print "! discrepancy of %.2f (%.2f - %.2f) between register and balance" % \
+ (balance_total - running_total, balance_total, running_total)
+ print last_line,
+ print line,
diff --git a/scripts/entry b/scripts/entry
new file mode 100755
index 00000000..28daf8c8
--- /dev/null
+++ b/scripts/entry
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if [ -z "$LEDGER" -o ! -r $LEDGER ]; then
+ echo Please set your LEDGER environment variable.
+fi
+
+line=`wc -l $LEDGER | awk '{print $1}'`
+
+if ledger entry "$@" > /tmp/entry; then
+ cat /tmp/entry >> $LEDGER
+else
+ echo "$@" >> $LEDGER
+fi
+rm /tmp/entry
+
+vi +$line $LEDGER
diff --git a/scripts/getquote b/scripts/getquote
new file mode 100755
index 00000000..cf8c8abd
--- /dev/null
+++ b/scripts/getquote
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+exit 0 if $ARGV[0] eq "\$";
+
+use Finance::Quote;
+
+$q = Finance::Quote->new;
+
+$q->timeout(60);
+$q->require_labels(qw/price/);
+
+%quotes = $q->fetch("nasdaq", $ARGV[0]);
+
+if ($quotes{$ARGV[0], "price"}) {
+ print "\$", $quotes{$ARGV[0], "price"}, "\n";
+}
diff --git a/scripts/mean b/scripts/mean
new file mode 100755
index 00000000..3c6f779a
--- /dev/null
+++ b/scripts/mean
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+$last = $ARGV[-1];
+splice(@ARGV, -1);
+
+open(PIPE, "ledger -MG @ARGV register $last |") || die;
+@values = ();
+while (<PIPE>) {
+ ($date, $value) = split;
+ push @values, $value;
+}
+close(PIPE);
+
+@values = sort @values;
+splice(@values, 0, 1);
+splice(@values, -1);
+
+$value = 0.0;
+for $item (@values) {
+ $value += $item;
+}
+
+if (@values) {
+ printf("%.2f\n", $value / @values);
+} else {
+ die "There are no values to average!\n";
+}
diff --git a/scripts/profit b/scripts/profit
new file mode 100755
index 00000000..26f112d1
--- /dev/null
+++ b/scripts/profit
@@ -0,0 +1,2 @@
+#!/bin/sh
+ledger "$@" balance ^Income$ ^Expenses$
diff --git a/scripts/reg b/scripts/reg
new file mode 100755
index 00000000..75ac364e
--- /dev/null
+++ b/scripts/reg
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+switch="-U"
+current="-c"
+
+if [ "$1" = "-C" -o "$1" = "-U" -o "$1" = "-P" -o "$1" = "-M" ]; then
+ switch="$1"
+ shift
+elif [ "$1" = "-b" -o "$1" = "-e" ]; then
+ current="$1 $2"
+ shift 2
+fi
+
+ledger $current -s $switch register "$@"
diff --git a/scripts/report b/scripts/report
new file mode 100755
index 00000000..c548792c
--- /dev/null
+++ b/scripts/report
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+args=("$@")
+last=${args[`expr ${#args} - 3`]}
+
+cd /tmp
+ledger "$@" | stripreg > $last
+
+gnuplot <<EOF
+set terminal png
+set output "report.png"
+set xdata time
+set timefmt "%Y/%m/%d"
+plot "$1" using 1:2 with linespoints
+EOF
+
+open report.png
diff --git a/scripts/spending b/scripts/spending
new file mode 100755
index 00000000..895c4170
--- /dev/null
+++ b/scripts/spending
@@ -0,0 +1,8 @@
+#!/bin/sh
+ledger "$@" balance \
+ Expenses:Food \
+ Expenses:Movies \
+ Expenses:Auto:Gas \
+ Expenses:Tips \
+ Expenses:Health \
+ Expenses:Supplies
diff --git a/scripts/stripreg b/scripts/stripreg
new file mode 100755
index 00000000..c974e646
--- /dev/null
+++ b/scripts/stripreg
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+
+import sys
+import re
+
+print_total = 0
+
+def clean(num):
+ return float(re.sub("(\s+|\$|,)","",num))
+
+for line in sys.stdin:
+ print line[:10],
+ if print_total:
+ print clean(line[68:80])
+ else:
+ print clean(line[55:67])
diff --git a/scripts/test b/scripts/test
new file mode 100755
index 00000000..7b17a1b2
--- /dev/null
+++ b/scripts/test
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+for test in \
+ "-O nrl:checking" \
+ "-B 401" \
+ "-V 401" \
+ "-G 401" \
+ "-B retire" \
+ "-V retire" \
+ "-G retire"
+do
+ echo testing: $test
+ python confirm.py $test
+done
diff --git a/scripts/version b/scripts/version
new file mode 100755
index 00000000..75cb06da
--- /dev/null
+++ b/scripts/version
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+cat ledger.cc | \
+ grep "^const std::string version" | \
+ sed 's/const std::string version = "\([0-9.A-Za-z]*\)";/\1/'
diff --git a/scripts/worth b/scripts/worth
new file mode 100755
index 00000000..58b20440
--- /dev/null
+++ b/scripts/worth
@@ -0,0 +1,2 @@
+#!/bin/sh
+ledger "$@" balance ^Assets$ ^Liabilities$