I asked OpenAi this question "can you make me a function in Harbour/ clipper language that takes the currency rates from the internet without using the access of Open Exchange Rates but of another non-paid service ?"
and gave me this answer
but i can't compile the source
- Code: Select all Expand view
#include "hbapi.h"
#include "hbapierr.h"
#include "hbapiitm.h"
#include "hbstack.h"
#include "curl/curl.h"
FUNCTION GetExchangeRates( cFromCurrency, cToCurrency )
LOCAL cUrl := "https://api.exchangeratesapi.io/latest?base=" + cFromCurrency + "&symbols=" + cToCurrency
LOCAL curl := curl_easy_init()
LOCAL cResult := ""
IF curl == NIL
RETURN NIL
ENDIF
curl_easy_setopt( curl, CURLOPT_URL, cUrl )
curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, 1 )
curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, { |buffer, size, nmemb, userp| buffer } )
curl_easy_setopt( curl, CURLOPT_WRITEDATA, @cResult )
IF curl_easy_perform( curl ) == CURLE_OK
LOCAL oJson := JsonToObj( cResult )
RETURN oJson.rates[cToCurrency]
ENDIF
curl_easy_cleanup( curl )
RETURN NIL
END FUNCTION
another questions
can you make me a function in Harbor/ clipper language that takes the currency rates from the internet without using the access of Open Exchange Rates but of another non-paid service (bank of Italy) and without using the libcurl library passing as parameter the date and the type of currency for example EUR
open Ai gave me this source
- Code: Select all Expand view
FUNCTION GetExchangeRates( cCurrency, dDate )
LOCAL cUrl := "https://www.bancaditalia.it/compiti/operazioni-cambi/serie-storiche/" + ;
TRANSFORM( YEAR( dDate ) ) + "-" + TRANSFORM( MONTH( dDate ), "@0" ) + "-" + ;
TRANSFORM( DAY( dDate ), "@0" ) + "/euro_valute_1/Valute_" + cCurrency + ".csv"
LOCAL cResult := UrlGet( cUrl )
LOCAL aLines := {}
LOCAL nLineCount := 0
LOCAL nRowIndex := 0
// Divide la stringa in righe
aLines := Explode( cResult, CRLF )
nLineCount := Len( aLines )
// Cerca la riga contenente i dati dei tassi di cambio
FOR nRowIndex := 1 TO nLineCount
IF AT( "data validita'", aLines[nRowIndex] ) > 0
EXIT
ENDIF
NEXT
// Se la riga è stata trovata, estrai i dati dei tassi di cambio
IF nRowIndex <= nLineCount
LOCAL aValues := {}
LOCAL nValueCount := 0
LOCAL nValueIndex := 0
// Divide la riga in colonne
aValues := Explode( aLines[nRowIndex], ";" )
nValueCount := Len( aValues )
// Cerca il valore corrispondente alla valuta richiesta
FOR nValueIndex := 1 TO nValueCount
IF AT( cCurrency, aValues[nValueIndex] ) > 0
RETURN Val( aValues[nValueIndex + 1] )
ENDIF
NEXT
ENDIF
// Se i dati dei tassi di cambio non sono stati trovati, restituisci 0
RETURN 0
END FUNCTION