- Timestamp:
- 01/12/25 17:15:36 (3 days ago)
- Branches:
- master
- Children:
- df7f390
- Parents:
- cd64b06
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
backend/GlobeGuru-backend/src/main/java/ScraperThread.java
rcd64b06 r0a7426e 14 14 import org.openqa.selenium.support.ui.WebDriverWait; 15 15 16 import javax.xml.crypto.Data; 16 17 import java.io.File; 17 18 import java.io.IOException; … … 164 165 }else continue; 165 166 166 DatabaseUtil.saveOptionDetails(option.getId(), type,board,amenity, price); 167 //Check for changes 168 int odId = checkForChanges(option.getId(), type, board,amenity,price); 169 if(odId != 0) { //true = changes found - update details 170 DatabaseUtil.updateOptionDetails(odId,type,board,amenity,price); 171 }else{ //false = not found / no changes - save regular 172 DatabaseUtil.saveOptionDetails(option.getId(), type, board, amenity, price); 173 } 167 174 } 168 175 } … … 194 201 } 195 202 System.out.println(type + board + price + amenities); 196 DatabaseUtil.saveOptionDetails(option.getId(), type, board, amenities.toString(), price); 197 } 198 199 } 203 int odId = checkForChanges(option.getId(), type, board,amenities.toString(),price); 204 if(odId != 0) { //true = changes found - update details 205 DatabaseUtil.updateOptionDetails(odId,type,board,amenities.toString(),price); 206 }else{ //false = not found / no changes - save regular 207 DatabaseUtil.saveOptionDetails(option.getId(), type, board, amenities.toString(), price); 208 } 209 } 210 211 } 212 } 213 private int checkForChanges(int id, String type, String board, String amenities, float price){ //return true for changes, false for no changes 214 try { 215 List<Option> pooled = DatabaseUtil.poolOptionDetails(id); 216 if (pooled.isEmpty()) { //not saved = no changes - save regular 217 return 0; 218 }else{ //got the options saved details 219 for(Option o : pooled){ 220 if(o.getType().equals(type) && o.getBoard().equals(board)){//for the room and board check amenity and price changes (Assumption type of room and board do not change) 221 if((!o.getAmenities().equals(amenities)) || o.getPrice() != price){ 222 return o.getDetail_id(); //Change 223 } 224 } 225 } 226 } 227 }catch(SQLException e){ 228 e.printStackTrace(); 229 } 230 return 0; //no changes detected 200 231 } 201 232 private Option optionParser(String data, int numPeople){ … … 218 249 return null; 219 250 } 220 //scrapeOptionInfo(created);221 251 return created; 222 252 } … … 235 265 Element countryElement = doc.selectFirst("l.ponuda-lokacija"); 236 266 created.setCountry(countryElement != null ? countryElement.text() : null); 237 //Element priceElement = doc.selectFirst("div.ponuda-cena");238 267 Element dateElement = doc.selectFirst("l.ponuda-opis.termin"); 239 268 created.setDateRange(dateElement != null ? dateElement.text() : null); 240 /*float price = Float.parseFloat(priceElement != null ? priceElement.text().replaceAll("[^\\d.]", "") : "0");241 created.setPrice(price);*/242 269 return created; 243 270 } … … 252 279 String country = countryP.text().replaceAll("leto hoteli", ""); 253 280 created.setCountry(country); 254 /*Element priceElem = doc.selectFirst("span.hotel-price");255 String priceText = priceElem.text();256 float price = 0;257 if(!priceText.isEmpty()) {258 price = Float.parseFloat(priceText.replace("€", ""));259 }260 created.setPrice(price);*/261 281 String[] queryParams = link.split("[?&]"); 262 282 String startDateStr = null;
Note:
See TracChangeset
for help on using the changeset viewer.