tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/4719-headless-access-for-moneydance-data-in-python-demonstration-and-codeInfinite Kind: Discussion 2021-11-23T10:50:20Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-07T19:33:58Z2021-02-07T19:33:58ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Very nice! I’m going to have a play with these!!</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-07T19:44:57Z2021-02-07T19:44:57ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Absolutely! You've done so much good work with python scripts in md, felt it was only fair that I should contribute something.</p></div>dalefurrow (Fellow User)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-07T20:11:45Z2021-02-07T20:11:45ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>I have been trying to work out how to call / run memorised reports and I think your scripts may do this, so I will take a peek.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-09T12:12:09Z2021-02-09T12:12:09ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Brilliant! Exactly what I have been lokking for!</p></div>george.dobbstag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-12T21:06:42Z2021-02-12T21:06:42ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Dale, I was able to get this to work (OK, mostly). Good stuff. I notice that it works well when no master password is set on the data file. I tried to work out a way to do that, but there is some hashing and crypto going on that I don't think I'll be able to figure out.</p>
<p>Looks like the place to pass in the password should be here:<br>
<code>wrapper.loadDataModel(None)</code> where None is replaced by something that implements<br>
<code>public interface com.moneydance.security.SecretKeyCallback</code></p>
<p>Might need to know more about how that interface works. By any chance did you have a go at this?</p></div>george.dobbstag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-12T21:16:08Z2021-02-13T18:12:01ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>I've had a nose around, it can be done, but it's a bit fiddly, certainly not standard, and requires some 'deep' java calls. You also have to reconstruct some code to make it work (so liable to brake in the future).. As Sean says on the next post, I have no idea what 'problems' this may create for your dataset, so probably not advisable... It would be great if Sean can make some standard API calls available in a future release..</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-12T21:58:23Z2021-02-12T21:58:23ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Please don't call methods like wrapper.loadDataModel()... bad things could happen. Let's work out a nice way to do this in a way that I can add to the official interface.</p>
<p>Would the simplest way to do this be to pass a URI on the command-line that is invoked once the data file is loaded? Presumably the URL would invoke an extension, but it could also reference a report or graph URL or some other common view.</p>
<p>Thanks,<br>
Sean</p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-12T22:21:56Z2021-02-12T22:21:56ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Hey George, I'll defer to Sean, possibly there's some sort of lock issue that might be a problem here...none of my data has been under password protection, and my primary use case for this has been either running regression tests for investment reports, or updating prices or security transactions, where it's helpful to be able to run java/python separate from the application with all the debug, logging, and inspection capability that you get from a regular ide. If there's a better way to do this, I'm all for it.</p></div>dalefurrow (Fellow User)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-12T22:29:23Z2021-02-12T22:29:23ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>I'm happy to take your advice on this.</p>
<p>I guess I was intrigued with the idea of being able to get access to my data and reports from "outside". That would improve some of my use-cases. For instance I could schedule the investment data loads and more easily export report data out to Excel.</p>
<p>I'm not sure I'm understanding what your URI scheme would entail, but it sort of sounds like Moneydance exposing an API to be called from the outside. Or maybe you are thinking of passing in a reference along with the command to start Moneydance in the first place.</p>
<p>I for one am definitely in favor of supported interfaces. In the meanwhile I can continue with Python 2.7 (Jython) internal and some cut and paste. Happy to take a look any ideas and provide on man's feedback. // George</p></div>george.dobbstag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-12T22:35:00Z2021-02-12T22:35:00ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>FYI - just a quick point - your data is always encrypted. If you haven’t set a master passphrase then an internal / default ‘secret’ encryption passphrase is used. As the moneydance code knows this ‘secret’ then it’s able to open the dataset of one is not set by the user.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-13T12:29:47Z2021-02-13T12:29:47ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Thanks for that note, Stuart. Good to know.</p>
<p>George Dobbs</p></div>george.dobbstag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-02-13T17:48:46Z2021-02-13T17:48:46ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Hi Sean, I guess the several points/questions are:<br>
1/ Some users would like to be able to load the dataset from Python outside of MD... I.e. dale is trying to do this with JPype (to link with the JVM). So can an API be exposed to do this (load the dataset and allow API calls to be made)?<br>
2/ I would like to be able to execute MD from the command line and pass a Python script parameter, extension parameter, report, to execute and then exit.. I've tried the method that's supposed to exist, but I could not get it working....?<br>
3/ For both 1 & 2 above (which are different requests), can a user specified passphrase be passed as an argument to decrypt the dataset if a user specified passphrase is set?</p>
<p>Thanks</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-04-12T15:09:00Z2021-04-12T15:09:00ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>@dalefurrow, @george.dobbs. I though I would have a play with this and also resolve the question posed about how to open and access the MD dataset headless when there is a user specific passphrase encryption set.. It works - see my revised code attached..</p>
<p>But do NOTE Sean's warning above. He advises against doing this. I take no responsibility for its usage.....!</p>
<p>As already discussed, we really need an API method and also a command line method to do this...</p>
<p>Let me know if you use this, and that it works ok?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-04-12T19:49:59Z2021-04-12T19:49:59ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>@Stuart, Thanks! I didn't have any examples of that. I haven't done much with this except to add a <a href="https://github.com/dkfurrow/md_python_headless_demo/blob/master/testmdheadless5.py">script</a> based on conversation with another user, trying to automatically trigger an import (which I definitely think would be better handled as a callable to some kind of url). As far as data safety, yeah, I use this only when the app is not open, so I'm only touching the data with <em>either</em> the app <em>or</em> the application but <em>never both simultaneously</em>, and of course I <strong>back up regularly</strong>. I've used this method for about 5 years with a self-built java app to download investment transactions, haven't had a problem yet. Ironically, it was Sean who gave me the original code, used for regression testing for investment reports extension <a href="https://github.com/dkfurrow/moneydance-investment-reports">here</a>. There's absolutely no way I would have continued to work on that project without headless access to do regression testing.</p></div>dalefurrow (Fellow User)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-04-12T19:57:40Z2021-04-12T19:57:40ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>To run a an import for example. Fairly easy. You could create a Python extension that loads at runtime and sits there waiting. Use the -invokeandquit parameter which will call .invoke() on your extension and the extension would receive the .invoke(), check the parameter and run the import etc.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-04-12T21:58:03Z2021-04-12T21:58:03ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>@ Stuart, yeah, I got that, but the user wanted to run the import as a scheduled job, outside of MD...any way you know to do that?</p></div>dalefurrow (Fellow User)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-04-13T07:05:53Z2021-04-13T07:05:53ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Most Os have a scheduling system. Eg Cron, task scheduler. You would have to play with these. I believe you can pass MD a ofx or qif import file name as a parameter and it will import that.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-04-14T13:11:27Z2021-04-14T13:11:27ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>An update... I've just installed Jython and I think this is perhaps a better approach to Python + JPype as it gives you more options (as it's all java based).</p>
<p>I have created a modified version of my launch script which sets up the JVM environment properly as Moneydance requires/expects when Jython launches.</p>
<p>You can run the launch shell script, which launches Jython (and thus the JVM with all the right settings etc), and runs your/my headless script(s) with a couple of tweaks. If anyone wants examples, shout....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-05T18:38:47Z2021-08-05T18:38:47ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>FYI in PREVIEW 2021.2(3089) - you can now set the environment variables</p>
<p>md_passphrase=yourpassphrase<br>
or<br>
md_passphrase_=yourpassphrase</p>
<p>and MD will read this to bypass the encryption passphrase popup entry box..</p>
<p>It seems to work running the normal app. I haven't yet tested using API.....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-07T14:12:39Z2021-08-07T14:12:39ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>I'm very pleased to report that the new MD2021.2(3088) feature that reads an environment viable to bypass the 'enter your password' prompt works well when loading Moneydance via a shell script, and then accessing the data using Jython from the shell.</p>
<p>One thing I've found is that you have to 'export' the variable from the shell script, and then it will work... Trying to set it within program just doesn't....</p>
<p>This means you can avoid the 'deep' methods that Sean advised against using above (post 7), and just use normal calls...</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-07T17:38:47Z2021-08-07T17:38:47ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Fantastic news, Stuart. I’ll definitely give it a try!</p>
<p>George Dobbs</p></div>george.dobbstag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-22T19:45:51Z2021-08-22T19:45:51ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Stuart,</p>
<p>I had good luck with the environment variable. It started up fine from a shell command</p>
<p>export md_passphrase<br>
/Applications/Moneydance\ 2.app/Contents/MacOS/Moneydance</p>
<p>But I'm not seeing how to do this from python.</p>
<p>I'm wondering if you would be so kind as to share how you invoked moneydance?</p>
<p>//George Dobbs</p></div>george.dobbstag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-22T19:53:59Z2021-08-22T19:53:59ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Look at the files/folders here:</p>
<p><a href="https://yogi1967.github.io/MoneydancePythonScripts/">https://yogi1967.github.io/MoneydancePythonScripts/</a></p>
<p>The links are at the bottom of the web site under the heading ‘Experimental / advanced’.</p>
<p>Let me know?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-22T20:44:57Z2021-08-22T20:44:57ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>To clarify further. You probably want these files:</p>
<p><a href="https://github.com/yogi1967/MoneydancePythonScripts/blob/master/external-access-jython/launch-moneydance-via-jython.sh">https://github.com/yogi1967/MoneydancePythonScripts/blob/master/ext...</a></p>
<p>and</p>
<p><a href="https://github.com/yogi1967/MoneydancePythonScripts/blob/master/external-access-jython/open_mdheadless_external_jython_with_environment_passphrase.py">https://github.com/yogi1967/MoneydancePythonScripts/blob/master/ext...</a></p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/490201582021-08-24T10:49:30Z2021-08-24T10:49:30ZHeadless Access for Moneydance Data in Python: Demonstration and Code<div><p>Thanks for these links. Good stuff!</p>
<p>George Dobbs</p></div>george.dobbs