v1.0.15 - Scraping primero, API como fallback
This commit is contained in:
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: BCV Exchange Rate Plugin
|
||||
Bundle-SymbolicName: com.venezuela.bcvrate;singleton:=true
|
||||
Bundle-Version: 1.0.14
|
||||
Bundle-Version: 1.0.15
|
||||
Bundle-Vendor: Ezerpa
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
||||
@@ -31,8 +31,25 @@ public class BCVApiService {
|
||||
|
||||
public BCVRateResponse getRateForDateWithFallback(String requestedDate) {
|
||||
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 {
|
||||
cal.setTime(sdf.parse(requestedDate));
|
||||
} catch (Exception e) {
|
||||
@@ -55,15 +72,7 @@ public class BCVApiService {
|
||||
cal.add(Calendar.DAY_OF_MONTH, -1);
|
||||
}
|
||||
|
||||
log.info("API no tiene tasa para " + requestedDate + ", intentando scraping BCV...");
|
||||
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);
|
||||
log.info("No se encontro tasa para: " + requestedDate);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user