[GNC] How to bulk import about 130 Securities entries?

Jim DeLaHunt list+gnucash at jdlh.com
Sun Aug 14 15:42:25 EDT 2022


Geoff:

On 2022-08-13 22:38, Geoff wrote:
> Hi Jim
>
> I don't have any experience manipulating GnuCash XML files, but in 
> principle what you want to do should work, although it does void your 
> GnuCash warranty.
>
> However, if you are going to all this effort you may find it more 
> worthwhile to invest your time in learning how to use a general 
> purpose automation tool.  This approach has two advantages over data 
> manipulation:
> (1) Automation drives the GnuCash GUI and thus protects you from 
> accidental data corruption.
> (2) You will be able to use your new automation skills to automate any 
> subsequent GnuCash tasks, for example loading historical transactions 
> to your 130 securities.

Thank you for this suggestion!

I think about XML files more often than I script application GUIs, so I 
did not even consider this approach.

I am on macOS. Apple has a built-in scripting system, with a language 
"AppleScript", which can perform GUI actions[1]. There is also a bridge 
to the Python language via the "PyAutoGUI" module[2].

I will give those a look. Maybe it will not just help me get my 130 
securities entered, it will also give me a reusable approach.

[1] 
<https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/AutomatetheUserInterface.html>
[2] <https://pypi.org/project/PyAutoGUI/>

Best regards,
      —Jim DeLaHunt

>
> For Windows, check out:
> AutoHotKey https://www.autohotkey.com/
> or:
> Power Automate Desktop https://powerautomate.microsoft.com/en-us/desktop/
>
> I can't recommend anything for Linux, but Google is your friend:
> https://alternativeto.net/software/autohotkey/?platform=linux
>
> Hope this helps.
>
> Regards
>
> Geoff
> =====
>
> On 14/08/2022 11:28 am, Jim DeLaHunt wrote:
>> Hello, folks:
>>
>> I am a long-time GnuCash user, and for all those years I have pretty 
>> much not attempted to track my investments in GnuCash. But now I want 
>> to start.  My first goal is to import many years of past activity.
>>
>> I have downloaded the transactions from my brokerage account as a CSV 
>> file. The first thing I get out of this is the name and symbol of 
>> about 130 securities. I am wondering if there is a practical way to 
>> bulk import these into GnuCash. That is, instead of visiting Tools -- 
>> Security Editor, and pressing the Add button 130 times, and filling 
>> out the "New security" dialogue 130 times, is there a more efficient 
>> path?
>>
>> Looking at the File… Import menu, I do not see an option to import 
>> Securities. Looking at the documentation, wiki, and list archives, I 
>> don't see a mention of this. Is there some bulk import mechanism I am 
>> overlooking?
>>
>> I took a look at the uncompressed XML contents of a new, simple 
>> .gnucash book file. It appears that the data entered in the "New 
>> security" dialogue gets stored as <gnc:commodity> entities. There 
>> appears to be a pretty simple relationship between the fields of the 
>> dialogue and the text within the <gnc:commodity> entity. The entities 
>> are stored in a certain order, sorted by <cmdty:space> then 
>> <cmdty:id>. There is a <gnc:count-data cd:type="commodity"> entity 
>> which seems to contain a text count of the non-CURRENCY gnc:commodity 
>> entries.
>>
>> This makes me wonder if I could transform my list of 130 security 
>> names and symbols into <gnc:commodity> entities, and insert them into 
>> the GnuCash XML of my book.
>>
>> Are there complexities or pitfalls about this approach which I might 
>> be overlooking?  We can certainly stipulate that manipulating the XML 
>> content directly is unsupported and risky, I must be careful and keep 
>> backups, I might blow off my fingers, etc.  For what it's worth, I 
>> believe that I am pretty proficient with editing XML, processing CSV 
>> files, and scripting manipulations of text data.
>>
>> Once I have the securities added to the book, I then need to add the 
>> appropriate child accounts to my brokerage accounts, each denominated 
>> in the appropriate security type and symbol. It looks like that is 
>> straightforward to do with a CSV of accounts in the correct format, 
>> and the File… Import…  Import Accounts from CSV… menu item. I have a 
>> few child accounts which I entered from the UI which will serve as 
>> examples.  Is there any way in which this is more difficult than it 
>> looks?
>>
>> Cheers,
>>       —Jim "ADBE ALNIX AOL … VUG VWO ZTD81" DeLaHunt
>>
>> _______________________________________________
>> gnucash-user mailing list
>> gnucash-user at gnucash.org
>> To update your subscription preferences or to unsubscribe:
>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>> -----
>> Please remember to CC this list on all your replies.
>> You can do this by using Reply-To-List or Reply-All.
>


More information about the gnucash-user mailing list