Skip to content

Instantly share code, notes, and snippets.

@Irwin1985
Created October 13, 2022 16:48
Show Gist options
  • Save Irwin1985/633e06f84820616d94f49eeaccba3d2b to your computer and use it in GitHub Desktop.
Save Irwin1985/633e06f84820616d94f49eeaccba3d2b to your computer and use it in GitHub Desktop.
* =====================================================================================
* Consulta las tasas del dolar desde el sitio web:
* https://www.datos.gov.co/resource/32sa-8pi3.json?vigenciadesde=
*
* Dependencias:
* VfpRestClient: https://github.com/Irwin1985/VFPRestClient
* JSONFox: https://github.com/Irwin1985/JSONFox
*
* NOTA:
* 1. Cambie las rutas de vfpRestClient y JSONFox por las correspondientes.
*
* Créditos especiales:
* Alejandro García Garay
* ===================================================================================== *
Local lcVfpRestClientDir, lcJsonFoxDir, loRest
lcVfpRestClientDir = "f:\desarrollo\github\vfprestclient\vfprestclient.prg"
lcJsonFoxDir = "f:\desarrollo\github\jsonfox\jsonfox.app"
Set Procedure To (lcVfpRestClientDir) Additive
lcDate = Date()
lcURL = 'https://www.datos.gov.co/resource/32sa-8pi3.json?vigenciadesde='
lcURLFin = 'T00:00:00.000'
lcDate = Alltrim(Str(Year(lcDate))) + "-" + Padl(Month(lcDate), 2, '0') + "-" + Padl(Day(lcDate), 2, '0')
*--- Se arma la dirección a consultar completa
lcURLTotal = lcURL + lcDate + lcURLFin
loRest = Createobject("Rest")
loRest.AddRequest(loRest.Get, lcURLTotal)
loRest.addHeader("Content-Type", "application/json")
loRest.Send()
If loRest.Status != 200
Messagebox(loRest.LastErrorText, 16, "Error")
Return
Endif
Do (lcJsonFoxDir)
_Screen.json.JSONToCursor(loRest.ResponseText, 'cData', Set("Datasession"))
Select cData
Browse
@agarciagaray
Copy link

Gracias por tu ayuda y colaboración siempre. Un saludos. Espero que le sirva a los compañeros.

@rodribezul
Copy link

Hola, cuando descargo el ultimo jsonfox.app, ya deja de funcionar el tema de la tasa

@Irwin1985
Copy link
Author

Hola, cuando descargo el ultimo jsonfox.app, ya deja de funcionar el tema de la tasa

Hola, el problema estaba en la cadena JSON que devuelve el servicio web ya que agrega caracteres no válidos, esto me ha servido para sanear la cadena de entrada justo antes de comenzar a convertir a JSON. Prueba ahora con la versión 9.9 que ya debe funcionar.

@rodribezul
Copy link

rodribezul commented Aug 11, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment