tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/2898-transactionset-for-date-range-in-pythonInfinite Kind: Discussion 2020-11-02T20:10:23Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/485067902020-08-03T18:03:25Z2020-08-03T18:03:26ZTransactionSet for date range in python<div><p>Hi, found this: <a href="https://infinitekind.tenderapp.com/discussions/moneydance-development/1379-transactionsetgettransactionsforaccount">https://infinitekind.tenderapp.com/discussions/moneydance-developme...</a><br>
I'm looking to do the same but using python.</p>
<p>This works to get all the transactions for the account: txns = moneydance_data.getTransactionSet().getTransactionsForAccount(account)<br>
but can't seem to figure out how to build the filter in python to limit the date range.</p>
<p>Any help appreciated!</p>
<p>Thanks</p></div>Jimtag:infinitekind.tenderapp.com,2009-01-14:Comment/485067902020-08-03T19:09:18Z2020-08-03T19:09:18ZTransactionSet for date range in python<div><p>Hi Jim,</p>
<p>Great question! We don't seem to have a call specifically for that, despite having a TxnFilter that ties into some controller/UI-level stuff. However, it might be best to do this in a python-y way, maybe with a lambda:</p>
<pre>
<code>from com.infinitekind.util import DateUtil
account = moneydance_data.getRootAccount().getAccountByName("Checking")
txns = moneydance_data.getTransactionSet().getTransactionsForAccount(account)
today = DateUtil.getStrippedDateInt()
first_date = DateUtil.incrementDate(today, -2, 0, 0)
for txn in filter(lambda x: first_date <= x.getDateInt() <= today, txns):
print(str(txn))</code>
</pre>
<p>Thanks,<br>
Sean</p>
<p>--<br>
Sean Reilly<br>
Developer, The Infinite Kind<br>
<a href="https://infinitekind.com">https://infinitekind.com</a></p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/485067902020-08-03T20:01:11Z2020-08-03T20:01:12ZTransactionSet for date range in python<div><p>Thanks for the quick reply. I had started to look at post-filtering the set. Your python-fu is much stronger than mine and this looks much more elegant than the brute-force code I would have come up with!<br>
Thanks!</p></div>Jimtag:infinitekind.tenderapp.com,2009-01-14:Comment/485067902020-08-03T20:02:16Z2020-08-03T20:02:16ZTransactionSet for date range in python<div><p>Ha, you're too kind. I always forget about lambda's and brute force things like that myself, but I have to admit I relied on DuckDuckGo for this one :)</p>
<p>--<br>
Sean Reilly<br>
Developer, The Infinite Kind<br>
<a href="https://infinitekind.com">https://infinitekind.com</a></p></div>Sean Reilly