Connect to other moneyman data

davidcullen's Avatar

davidcullen

10 Apr, 2019 01:01 AM

Excuse me if this is obvious.
I'm using jython to interact with txns.
When I use:
root = moneydance.getCurrentAccount() book = moneydance.getCurrentAccountBook() txnset = book.getTransactionSet
I can then access txns in the current moneydance file.
How can I also access another moneydance database (say /Users/david/Desktop/Moneydance/cullenFinances.moneydance) at the same time so I can access txns on that db at the same time as accessing txns on the first db? Currently, I open in md the first file and then dump to csv then open the second file to read the csv and access the second db txns. I would like to avoid the csv file as intermediary.

  1. 1 Posted by Mike Bray (Quot... on 11 Apr, 2019 06:37 PM

    Mike Bray (Quote Loader Author)'s Avatar

    Hi

    It is not really possible to access another file. MD's files are an internal structure and the only way to access them is to open them within MD one at a time. Any extensions/python scripts act on the currently opened file.

    Mike Bray(a fellow user, not MD Support)

  2. 2 Posted by davidcullen on 11 Apr, 2019 10:48 PM

    davidcullen's Avatar

    Thanks for the reply. I’ll keep using csv as a stepping stone. It works, just have to remember csv data is all strings, not original int , etc, for use in later filter with other txnset.

    Sent from my iPad

  3. 3 Posted by davidcullen on 12 Apr, 2019 06:16 AM

    davidcullen's Avatar

    For interest of anyone, here are the script I used successfully to dump and then read/process csv file:
    Some txn tags in newMoneyDance have their keyword deleted accidentally and need to be put back.
    This script dumps oldMoneyDance txns to csv file, forcing keyword to lowercase, which 2nd script imports into newMoneyDance as needed.

    # -- coding: UTF-8 --
    from com.infinitekind.moneydance.model import *
    import java.util.ArrayList 
    import csv
    root = moneydance.getCurrentAccount()
    book = moneydance.getCurrentAccountBook()
    txnset = book.getTransactionSet()
    txns = filter(lambda  x:x.class.name == "SplitTxn" and x.getKeywords().size() == 1 and x.getKeywords()[0].encode("utf-8") <> x.getKeywords()[0].encode("utf-8").lower(), txnset) 
    csvLines = java.util.ArrayList()
    csvLines.add(["Account","ParentAccount","DateInt","Value","Tag"]) 
    for txn in txns:
      a = txn.getAccount()
      b = txn.getParentTxn().getAccount()
      c = txn.getDateInt()
      d = txn.getValue()
      e = txn.getKeywords()[0].encode("utf-8").lower()
      newline = [a,b,c,d,e]
      csvLines.add(newline) 
    with open("/Users/david/Desktop/txnDump.csv", "w") as f:
      csv.writer(f).writerows(csvLines)
    
    and:
    # -- coding: UTF-8 --
    from com.infinitekind.moneydance.model import *
    import java.util.ArrayList 
    import csv 
    root = moneydance.getCurrentAccount()
    book = moneydance.getCurrentAccountBook()
    txnset = book.getTransactionSet()
    txns = filter(lambda  x:x.class.name == "SplitTxn" and x.getKeywords().size() == 0, txnset) 
    with open("/Users/david/Desktop/txnDump.csv") as myFile:
    reader = csv.DictReader(myFile) for row in reader: found = filter(lambda x:x.getDateInt() == int(row["DateInt"]) and str(x.getAccount()) == row["Account"] and str(x.getParentTxn().getAccount()) == row["ParentAccount"] and x.getValue() == int(row["Value"]), txns) if len(found) == 1: tag = java.util.ArrayList() # new empty ArrayList tag.add(row["Tag"]) found[0].setKeywords(tag)
  4. davidcullen closed this discussion on 12 Apr, 2019 06:16 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

14 Dec, 2024 07:05 PM
14 Dec, 2024 06:35 PM
14 Dec, 2024 06:22 PM
14 Dec, 2024 05:15 PM
14 Dec, 2024 03:08 PM