Page MenuHomePhabricator

How to use pywikibot to get data from SMW ask API?
Open, Needs TriagePublic


The SemanticMediaWiki extension has it's own Mediawiki API extensions see
I'd like to use pywikbot to use these API functions and created the following pyunit test:

api=APIGenerator("ask",query="[[Topic name::Fixme]]",site=site)
           for item in api:
               print (item)

When i try this i get:

WARNING: API warning (main): Unrecognized parameter: 'continue'

Event Timeline

I see. SMW does not have the MW api continue system but an offset parameter which must be given to the query string delimited by "|" i guess. The returned Offset is not response['continue']['continue'] but there is query-continue-offset key insid the response dict. Look like we need either a meta parameter for SMW api or a separate Class to handle this.

@Xqt - thanks for looking into this. I am currently adding this to with where I am happily using a standard Request for the time being to simplify things. It seems that APIGenerator adds caching handling and some legacy stuff as well as continuation - for the time being i'd focus more on the core functionality of unpacking the printrequest structures delivered and being able to use cut&paste for ask queries. The implementation will be mostly along the lines of where this was already succesfully implemented in Java.

The SMW support now works quite nicely to handle the SMW API. This task can IMHO be closed.

Feel free to share how you resolved the issue

from import Request

def submit(self, parameters):
        """ submit the request with the given parameters
            parameters(list): the parameters to use for the SMW API request
            dict: the submit result"""
        return request.submit()    

def rawquery(self,ask):
        """ send a query see
            ask(str): the SMW ASK query as it would be used in MediaWiki markup"""
        # allow usage of original Wiki ask content - strip all non needed parts
        # set parameters for request
        parameters={"action": "ask","query":fixedAsk}
        return result

from there it was all "downhill" since the deserialization code is similar to the Java solution i already had done and this is Semantic Media Wiki specific.