Internet in LO/OO BASIC

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
psilocybe
Posts: 107
Joined: Thu Jun 15, 2017 5:33 am

Internet in LO/OO BASIC

Post 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.
LibreOffice 5.3.3.2 - Lubuntu 16.10 - LxQt 0.11.0.3
Mountaineer
Posts: 310
Joined: Sun Sep 06, 2020 8:27 am

Re: Internet in LO/OO BASIC

Post 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
OpenOffice 3.1 on Windows Vista
psilocybe
Posts: 107
Joined: Thu Jun 15, 2017 5:33 am

Re: Internet in LO/OO BASIC

Post 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.
LibreOffice 5.3.3.2 - Lubuntu 16.10 - LxQt 0.11.0.3
Post Reply