Created
March 3, 2018 15:05
-
-
Save simonmichael/06eed26bcc85c76d1604373418bc6c58 to your computer and use it in GitHub Desktop.
XpenseTracker -> hledger makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# XpenseTracker iOS app -> hledger import & reports | |
# | |
# Fetch csv files from XpenseTracker iphone app (requires curl, funzip). | |
# Procedure: | |
# connect phone and computer to same network | |
# make csv | |
# start XpenseTracker app | |
# enter each XpenseTracker log, as prompted on computer | |
# (first time: options, set appropriate CSV fields) | |
# options, export, export | |
# (if phone shows IP different from above, ctrl-c, adjust IP below, redo) | |
# computer prints ok and prompts for next log | |
# | |
PHONEIP=192.168.0.3 | |
# one per XT log | |
CSVFILES=\ | |
2017-business.csv \ | |
2017-personal.csv \ | |
# 2018-business.csv \ | |
# 2018-personal.csv \ | |
JOURNALS=\ | |
2017-business.journal \ | |
2017-personal.journal \ | |
# 2018-business.journal \ | |
# 2018-personal.journal \ | |
REPORTS= \ | |
out/2017-business-is.html \ | |
out/2017-business-is-summary.html \ | |
out/2017-personal-is.html \ | |
out/2017-personal-is-summary.html \ | |
out/2017-business-is.csv \ | |
out/2017-business-is-summary.csv \ | |
out/2017-personal-is.csv \ | |
out/2017-personal-is-summary.csv \ | |
REPORTOPTS=-MAT --flat --drop 1 | |
REPORTOPTSSUMMARY=$(REPORTOPTS) depth:2 | |
.PHONY: $(CSVFILES) $(JOURNALS) $(REPORTS) | |
default: journals reports open | |
# FETCH CSV | |
csv: $(CSVFILES) | |
CURLOPTS=-s #--connect-timeout 1 | |
# Fetch, unzip, clean space-terminated account names, report success/failure | |
$(CSVFILES): | |
@echo "waiting for $(@:.csv= log) from $(PHONEIP) ..." | |
@(curl $(CURLOPTS) 'http://$(PHONEIP):8080/XT Export.zip' | funzip >$@.tmp 2>/dev/null && echo ok || (echo failed; false)) \ | |
&& (mv $@.tmp $@ && perl -pi -e 's/ :/:/' $@) \ | |
|| rm -f $@.tmp | |
# CONVERT ALL TXNS TO JOURNAL | |
journals: $(JOURNALS) | |
# recreate journal from csv, and include corresponding accounts file | |
$(JOURNALS): | |
[[ -x $@ ]] || printf "# converted from $(@:.journal=.csv)\n\ninclude $(@:.journal=.accounts)\n\n" > $@ | |
hledger -f $(@:.journal=.csv) print >> $@ | |
# IMPORT NEW TXNS TO JOURNAL | |
# # make 2018-business-import: import new csv txns to this journal | |
# %-import: | |
# hledger import -f $*.journal $*.csv | |
# # YEAR-import-dry: convert YEAR csv and show new transactions | |
# %-import-dry: | |
# hledger import -f $*.journal $**.csv --dry-run | |
# # YEAR-import-dry-watch: convert YEAR csv and show first N new transactions, repeatedly | |
# %-import-dry-watch: | |
# ls $**.csv* | entr bash -c "echo; date; echo; hledger import -f $*.journal $**.csv --dry-run | head -20" | |
# # YEAR-import-unknowns-watch: convert YEAR csv and show uncategorised new transactions, repeatedly | |
# %-import-unknowns-watch: | |
# ls $**.csv* | entr bash -c "echo; date; echo; hledger import -f $*.journal $**.csv --dry-run | hledger -I -f- print unknown" | |
# GENERATE CSV REPORTS FROM CSV | |
# # Generate per-log csv income statement reports from csv and open in Numbers. | |
# reports-from-csv: \ | |
# 2017-business-monthly-is.csv \ | |
# 2017-personal-monthly-is.csv \ | |
# 2017-%-monthly-is.csv: #2017-$*.csv | |
# hledger -f 2017-$*.csv bal -M ^income ^expenses depth:2 -o $@ && open -a Numbers $@ | |
# GENERATE CSV REPORTS FROM JOURNAL | |
# # Generate csv income statement reports from journals and open in Numbers. | |
# %-is.csv: #$*.journal | |
# hledger -f $*.journal is -M depth:2 -o $@ && open -a Numbers $@ | |
# # hledger -f $*.journal bal ^income ^expenses -M depth:2 -o $@ && open -a Numbers $@ | |
# GENERATE REPORTS FROM JOURNAL | |
reports: $(REPORTS) | |
# Generate per-year html income statement reports from journals | |
#$(REPORTS): | |
out/2017-business-is.html \ | |
out/2017-personal-is.html: | |
hledger -f $(subst out/,,$(@:-is.html=.journal)) is -o $@ $(REPORTOPTS) | |
#%-summary.html: | |
out/2017-business-is-summary.html \ | |
out/2017-personal-is-summary.html: | |
hledger -f $(subst out/,,$(subst -is-summary.html,.journal,$@)) is -o $@ $(REPORTOPTSSUMMARY) | |
out/2017-business-is.csv \ | |
out/2017-personal-is.csv: | |
hledger -f $(subst out/,,$(@:-is.csv=.journal)) is -o $@ $(REPORTOPTS) | |
out/2017-business-is-summary.csv \ | |
out/2017-personal-is-summary.csv: | |
hledger -f $(subst out/,,$(subst -is-summary.csv,.journal,$@)) is -o $@ $(REPORTOPTSSUMMARY) | |
# BROWSE HTML REPORTS | |
open: | |
open $(REPORTS) | |
# MISC | |
clean: | |
rm -f $(JOURNALS) | |
rm -f $(REPORTS) | |
Author
simonmichael
commented
Jun 6, 2019
via email
Nice process! Consider adding it to the Cookbook.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment