git ssb

0+

cel / ledger-scripts



Commit 6884ee53582a72b95a4a0d125dab4341218f8fd8

Add ust-bonds-interest script

Charles Lehner committed on 12/16/2015, 4:57:13 PM
Parent: 6d582dbad9c458fe3686a9701278abbc3353914e

Files changed

Makefilechanged
README.mdchanged
ust-bonds-interestadded
MakefileView
@@ -1,7 +1,7 @@
11 symlinks = merge-ledger getquote gethistoric cryptotrade2ledger \
22 dwolla2ledger fidelity2ledger lbcsv2ledger mint2ledger \
3- paypal2ledger
3+ paypal2ledger ust-bonds-interest
44
55 prefix = /usr/local
66 exec_prefix = $(prefix)
77 bindir = $(exec_prefix)/bin
README.mdView
@@ -129,8 +129,36 @@
129129
130130 Merge multiple ledger journals into one, in time order, without detecting
131131 duplicates.
132132
133+#### `usd-bonds-interest`
134+
135+Retrieve accrued interest on US Treasury savings bonds. This script queries the
136+[Savings Bond Calculator][sbc] on the TreasuryDirect website and looks up the
137+difference in total value of some bonds between two dates. To use the script
138+you have to set an environmental variable `BONDS_QUERY` to the query string you
139+would submit to the savings bond calculator. To figure out what value to use
140+for the query string, do the following:
141+
142+- Go to the [Savings Bond Calculator][sbc] page
143+- Add the bonds using the form
144+- Right click somewhere in the form and choose "Inspect Element" to open the
145+ web inspector
146+- Find the `<form>` element in the web inspector
147+- Change the `method` attribute of the `<form>` from `post` to `get`
148+- Close the web inspector
149+- Submit the form using the View or Save button
150+- Get the URL of the resulting page. Copy the query string starting at
151+ `Series=` (not including `RedemptionDate=...&`)
152+- Set the env var to the copied query string e.g. by executing `export
153+ BONDS_QUERY="..."`
154+- Now you can run the script, e.g. `ust-bonds-interest 11/2015 12/2015` to get
155+ interested accrued between 11/2015 and 12/2015.
156+
157+[sbc]: http://www.treasurydirect.gov/BC/SBCPrice
158+
159+*TODO: automate more of this*
160+
133161 Similar projects
134162 ----------------
135163
136164 * [ledger-bitcoin](https://github.com/profmaad/ledger-bitcoin) by
ust-bonds-interestView
@@ -1,0 +1,27 @@
1+#!/bin/sh
2+# ust-bonds-interest - get interest on treasury bonds
3+
4+get_value() {
5+ wget -qO- \
6+ "http://www.treasurydirect.gov/BC/SBCPrice?$query&RedemptionDate=$1" |\
7+ sed -n '/colspan="6"/!d; n; n; n; n
8+ s/.*<td>//; s/<\/td.*//; s/[$,]//g; p'
9+}
10+
11+get_diff() {
12+ query="${BONDS_QUERY?BONDS_QUERY env var must be set}"
13+ amt1=$(get_value $1)
14+ amt2=$(get_value $2)
15+ echo \$$(echo $amt2 - $amt1 | bc -l)
16+}
17+
18+usage() {
19+ echo Usage: $0 start_date end_date
20+ echo Date format: mm/yyyy
21+}
22+
23+case $# in
24+ 0) usage;;
25+ 2) get_diff $@;;
26+ *) usage >&2; exit 1;;
27+esac

Built with git-ssb-web