v1.0.15 - Scraping primero, API como fallback

This commit is contained in:
2026-07-03 19:23:59 -04:00
parent 16455abff5
commit 99081dbf88
2 changed files with 20 additions and 11 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: BCV Exchange Rate Plugin Bundle-Name: BCV Exchange Rate Plugin
Bundle-SymbolicName: com.venezuela.bcvrate;singleton:=true Bundle-SymbolicName: com.venezuela.bcvrate;singleton:=true
Bundle-Version: 1.0.14 Bundle-Version: 1.0.15
Bundle-Vendor: Ezerpa Bundle-Vendor: Ezerpa
Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
@@ -31,8 +31,25 @@ public class BCVApiService {
public BCVRateResponse getRateForDateWithFallback(String requestedDate) { public BCVRateResponse getRateForDateWithFallback(String requestedDate) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
log.info("Buscando tasa para fecha solicitada: " + requestedDate);
log.info("Intentando scraping BCV website...");
BCVRateResponse websiteRate = getRateFromBCVWebsite();
if (websiteRate != null && websiteRate.isValid()) {
String scrapedEffectiveDate = websiteRate.getDate();
if (!scrapedEffectiveDate.equals(requestedDate)) {
log.info("Scraping BCV: tasa del " + scrapedEffectiveDate
+ " aplica para " + requestedDate);
} else {
log.info("Scraping BCV: tasa del " + scrapedEffectiveDate
+ " coincide con fecha solicitada");
}
return new BCVRateResponse(websiteRate.getDollar(), requestedDate, scrapedEffectiveDate);
}
log.info("Scraping BCV no disponible, buscando en API hacia atras...");
Calendar cal = Calendar.getInstance();
try { try {
cal.setTime(sdf.parse(requestedDate)); cal.setTime(sdf.parse(requestedDate));
} catch (Exception e) { } catch (Exception e) {
@@ -55,15 +72,7 @@ public class BCVApiService {
cal.add(Calendar.DAY_OF_MONTH, -1); cal.add(Calendar.DAY_OF_MONTH, -1);
} }
log.info("API no tiene tasa para " + requestedDate + ", intentando scraping BCV..."); log.info("No se encontro tasa para: " + requestedDate);
BCVRateResponse websiteRate = getRateFromBCVWebsite();
if (websiteRate != null && websiteRate.isValid()) {
log.info("Tasa obtenida del sitio web BCV: USD=" + websiteRate.getDollar()
+ " effective=" + websiteRate.getDate());
return new BCVRateResponse(websiteRate.getDollar(), requestedDate, websiteRate.getDate());
}
log.info("No se encontro tasa en los ultimos " + MAX_DAYS_BACK + " dias para: " + requestedDate);
return null; return null;
} }