Linked Questions

Popular Questions

I implemented a simple addin in python to retrieve stocks prices and other data via an API. It works ok, however I have many tickers and the whole thing blocks for a few minutes because each cell is evaluated one by one and the latency to the API just adds up.

Is there any way to launch a thread and return a temporary "loading..." value and repopulate the cell with data when it becomes available? I've tried doing it but the documentation is very scarce and I couldn't find out how to populate the data from the threads after the requests finishes.

The code is simple and looks like this:

import json
import urllib.request

import uno
import unohelper
from com.stizard.api import XStizardApi

class StizardImpl(unohelper.Base, XStizardApi):
    def __init__(self, ctx):
        self.ctx = ctx
    def stizardPrice(self, symbol):
        with urllib.request.urlopen("" + symbol) as response:
            rawResponse =
            data = json.loads(rawResponse)
            return data['price']
    def stizard(self, symbol, q = "price"):
        with urllib.request.urlopen("" + symbol +"&q=" + q) as response:
            rawResponse =
            data = json.loads(rawResponse)
            return data['price']

def createInstance(ctx):
    return StizardImpl(ctx)
g_ImplementationHelper = unohelper.ImplementationHelper()

Later edit: idl file XStizardApi.idl

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

module com { module stizard { module api {

    interface XStizardApi {
        double stizardPrice( [in] string symbol );
        string stizard( [in] string symbol, [in] string q);

}; }; };


<?xml version="1.0" encoding="UTF-8"?>
<description xmlns=""

    < value="2.4" d:name=" 2.4"/>

<identifier value="com.stizard.api" />
<version value="1.0.0" />
<display-name><name lang="en">Stizard API</name></display-name>
<publisher><name xlink:href="" lang="en"></name></publisher>


Related Questions