Someone asked me to download the exchange rates for various currencies online and therefore, not knowing how to do it, I asked OpenAi
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
another questions
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
#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 FUNCTIONanother 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 EURopen Ai gave me this source
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 FUNCTIONSince from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

