Page 1 of 1

Internet in LO/OO BASIC

Posted: Wed Apr 19, 2023 12:09 pm
by psilocybe
Hi all,

How do you access the internet with LibreOffice/OpenOffice Basic, what are the tools?
To be more precise: is it possible to fill a Calc file with data from a web page in JSON, XML, and why not HTLM format?

Thanks.

Re: Internet in LO/OO BASIC

Posted: Thu Apr 20, 2023 8:16 am
by Mountaineer
BASIC as a language is not aware of anything like the internet and will provide nothing. You may load files, if the OS or LibreOffice helps: You can use file:-URLs, but to parse any modern stuff like xml, json etc you are on your own or need a library.

Obviously there is library-code available for xml and html in UNO, because LO uses XML itself and can import html.

But actually I would start searching here, as there is a Calc-service, wich can import data to a Calc-grid and it may be easier to use the existing options:
https://wiki.documentfoundation.org/Doc ... WEBSERVICE

Re: Internet in LO/OO BASIC

Posted: Thu Apr 20, 2023 11:49 am
by psilocybe
Hi Mountainner,

Thank you for the WEBSERVICE link I did not know and it gives a starting point.

In fact for my extensions I use the Python Request API, one of the easiest HTTP request APIs to use.
As I use it from different extensions, I finally managed to port the Request API to UNO and should therefore also be accessible to BASIC.

This port of the Request API provides two new interfaces under UNO: These two new interfaces try to mimic as closely as possible that of the Request API, especially for XRequestResponse which allows:
  • To know the status of the HTTP request.
  • To access the content of the request as a binary stream XEnumeration.
  • To manage the tokens of the following pages found in the JSON or XLM APIs of google Drive API or Microsoft graph, allowing the execution of requests in a loop.
The use is very simple:
  • Create the UNO service:

    Code: Select all

    session = CreateUnoService("io.github.prrvchr.OAuth2OOo.OAuth2Service")
  • If you want to use OAuth2 initialize session (optionnal):

    Code: Select all

    session.initializeSession(url, emailaddress)
  • Get a Request Parameter:

    Code: Select all

    parameter = session.getRequestParameter("aname")
  • Set a least an URL and the NoAuth properties (the default HTTP request method is GET):

    Code: Select all

    parameter.Url = "https://...."

    Code: Select all

    parameter.NoAuth = true
  • Get the HTTP response from parameter:

    Code: Select all

    response = session.execute(parameter)
  • do what you have to do with your response then:

    Code: Select all

    response.close()
With this new UNO API, I think it will be quite easy for the OAuth2Service service to offer a method:

Code: Select all

pullToCalc(XRequestParameter, ThisComponent, contenttype)
(with contenttype as a ContentType) allowing to suck web pages in Calc.

I have to create a dialog box to set the properties of XRequestParameter, that's not too complicated.
The Calc part is accessing the correct cell and injecting the data. For this part I cruelly lack skills.