yahooticker - A LibreOffice Calc Add-in

yahooticker - A LibreOffice Calc Addin

The add-in itself, an .oxt file, which is essentially just a renamed .zip file, consist of the following five files:

1. description.xml

2. manifest.xml

3. ytCalcAddIn.xcu

4. XYahooTicker.idl



<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="" 
	< value="2.4" d:name=" 2.4"/>
<identifier value="com.olivermahmoudi.programming.yahooticker" />
<version value="0.1" />
<display-name><name lang="en">Yahoo Stock Ticker Function.</name></display-name>
<publisher><name xlink:href="" lang="en">Oliver Mahmoudi</name></publisher>


<manifest:file-entry manifest:media-type="application/;type=RDB" 
<manifest:file-entry manifest:media-type="application/" 
<manifest:file-entry manifest:media-type="application/;type=Python" 


<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="" xmlns:xs="" oor:name="CalcAddIns" oor:package="org.openoffice.Office">
<node oor:name="AddInInfo">
<node oor:name="com.olivermahmoudi.programming.yahooticker.python.YahooTickerClass" oor:op="replace">
<node oor:name="AddInFunctions">
<node oor:name="yahooticker" oor:op="replace">
	<prop oor:name="DisplayName"><value xml:lang="en">yahooticker</value></prop>
	<prop oor:name="Description"><value xml:lang="en">Returns the current market price of the instrument that is passed to the function.</value></prop>
    <prop oor:name="Category"><value>Add-In</value></prop>
    <prop oor:name="CompatibilityName"><value xml:lang="en">AutoAddIn.YahooTicker.yahooticker</value></prop>

		<node oor:name="Parameters">
			<node oor:name="instrument" oor:op="replace">
	        <prop oor:name="DisplayName"><value xml:lang="en">instrument</value></prop>
    	    <prop oor:name="Description"><value xml:lang="en">Instrument to query.</value></prop>


#include <com/sun/star/uno/XInterface.idl>

module com { module olivermahmoudi { module programming { module yahooticker {

    interface XYahooTicker
      double yahooticker( [in] string instrument );

}; }; }; };

And here goes the python source code:

import uno
import unohelper
import requests
import re

from com.olivermahmoudi.programming.yahooticker import XYahooTicker

class YahooTickerClass( unohelper.Base, XYahooTicker ):
	def __init__( self, ctx ):
		self.ctx = ctx

	def yahooticker( self, instrument ):
		"Query yahoo finance with instrument return instrument's current market value"
		yahoo_base_url = ""
		url_to_query = yahoo_base_url + instrument
			ws = requests.get(url_to_query)
		except requests.exceptions.RequestException as e:
			print e
		content = ws.text
		regex = re.compile(r"<!--\sreact-text:\s36\s-->[0-9]+,?[0-9]*\.[0-9]+<!--\s/react-text\s-->")
		result =
		if result:							# We have found something...
			regex = re.compile(r"[0-9]+,?[0-9]*\.[0-9]+")	        # Extract
			result =			# the price
			return				        # and return it...
			return "Nothing found"					# Futile search
def createInstance( ctx ):
	return YahooTickerClass( ctx )

g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation( \

If you want to compile the above files yourself, you will need the LibreOffice SDK. This can either be obtained on the LibreOffice homepage or via your package manager.

To initiate the sdk, you will need to run a number of scripts, provided by the sdk itself, to initiate the environment. Depending on where you obtained the sdk from, these scripts may be in a different location on your computer. On my CentOS7 system, these scripts happen to be in the following locations:




These steps are necessary, as you will need the idlc and regmerge utlilities to compile the idl file into an .rdb file.

For the sake of convenience, I've combined the two sdk initiation steps and put them into the following short shell script:


# Initiate the libreoffice sdk

exit 0

Now we can "compile" the add-in itself. As noted above, we will need to make use of the zip utility and later on rename the archive to and .oxt file, which can in turn be registered with LibreOffice.

The following script takes care of both, generating the .rdb file and creating the add-in itself.


# Compile the .rdb file.
idlc -I /usr/lib64/libreoffice/sdk/idl idl/XYahooTicker.idl
regmerge idl/XYahooTicker.rdb /UCR idl/XYahooTicker.urd

# Delete the .urd file, as it's just of temporary need.
rm -v idl/XYahooTicker.urd

# Move the .rdb file to its destination.
mv -i idl/XYahooTicker.rdb ./

# In case there is an old .oxt file delete it.
rm -vf yahooticker.oxt

# zip the source files.
zip \
	META-INF/manifest.xml \
	ytCalcAddIn.xcu \
	XYahooTicker.rdb \
	description.xml \

# An .oxt file is actually just a .zip file.
mv -i yahooticker.oxt

exit 0

Running the last script, generates the add-in called yahooticker.oxt

To register the add-in with the system, open LibreOffice and go to Tools -> Extension Manager -> Add... and open the file yahooticker.oxt. This will enable the function: YAHOOTICKER in Calc, which can be used to obtain the current market value of your favourite instrument.