Script attached in-case spaces gets munged up by the list server which I
already show done so.
-----Original Message-----
From: Kalpesh Patel <[email protected]>
Sent: Tuesday, August 11, 2026 4:34 PM
To: 'Wm Tarr' <[email protected]>; '[email protected]'
<[email protected]>
Subject: RE: [GNC] Trading accounts
Here is the Python script that will do so. You'll need to provide full path to
your compressed XML data file as the first argument, followed by list of
symbols to find namespace(s) for. All parameters separated by one or more
spaces.
Example
c:\CloudDrives\OneDrive\QuickenStuff\HELPERS>python display_namespaces.py
c:\data\gnucash\example.gnucash NANC NANC:CBOE NANC:CBOE - US
You will need Python 3.X installed, along with lxml and gzip libraries
installed in Python for the script to work. You would copy & paste everything
between '# ---' delimiters to a file for a fully running script.
Now you have both ways to do it. Hope these helps.
# --- Start of Script
from lxml import etree
import gzip
import sys
if len(sys.argv) > 2:
tickers = [ticker.strip() for ticker in sys.argv[2:]]
data_file = sys.argv[1]
else:
print ("\nProvide two positional parameters:")
print (" File name as the first.")
print (" Specify one or more tickers as second and onward separated by a
space.")
exit()
with gzip.open(data_file, "rb") as f:
context = etree.iterparse(f,
tag='{http://www.gnucash.org/XML/gnc}commodity')
for event, elem in context:
symbol = elem[1].text
namespace = elem[0].text
elem.clear()
if any(symbol.lower() == ticker.lower() for ticker in tickers):
print ("{}:{}".format(symbol, namespace)) # --- End of
Script
-----Original Message-----
From: Wm Tarr <[email protected]>
Sent: Monday, August 10, 2026 12:56 PM
To: [email protected]
Subject: Re: [GNC] Trading accounts
I don't think you can do it in gnc but here is some SQL that does it
===
with m_cnt as (
select mnemonic, count(*) as cnt
from commodities
group by mnemonic
having cnt > 1
)
select namespace, mnemonic
from commodities
where mnemonic in (select mnemonic from m_cnt)
;
===
Wm
On 2026-08-10 01:36, Fred Tydeman wrote:
>
> Anyone know of a way to find stocks in more than one Namespace?
>
>
from lxml import etree
import gzip
import sys
if len(sys.argv) > 2:
tickers = [ticker.strip() for ticker in sys.argv[2:]]
data_file = sys.argv[1]
else:
print ("\nProvide two positional parameters:")
print (" File name as the first.")
print (" Specify one or more tickers as second and onward separated by a
space.")
exit()
with gzip.open(data_file, "rb") as f:
context = etree.iterparse(f,
tag='{http://www.gnucash.org/XML/gnc}commodity')
for event, elem in context:
symbol = elem[1].text
namespace = elem[0].text
elem.clear()
if any(symbol.lower() == ticker.lower() for ticker in tickers):
print ("{}:{}".format(symbol, namespace))
_______________________________________________
gnucash-user mailing list
[email protected]
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.