Changeset cd64b06 for backend/GlobeGuru-backend
- Timestamp:
- 01/11/25 01:23:10 (5 days ago)
- Branches:
- master
- Children:
- 0a7426e
- Parents:
- 1c51912
- Location:
- backend/GlobeGuru-backend
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
backend/GlobeGuru-backend/src/main/java/DatabaseUtil.java
r1c51912 rcd64b06 151 151 "FROM options o " + 152 152 "LEFT JOIN optionDetails od ON o.id = od.optionId " + 153 "WHERE (o.country LIKE ? OR o.hotelName LIKE ?)"; 153 "WHERE (o.country LIKE ? OR o.hotelName LIKE ?) " + 154 "AND od.type IS NOT NULL " + 155 "AND od.board IS NOT NULL " + 156 "AND od.price > 0"; 154 157 155 158 if (dateQuery != null && !dateQuery.isEmpty() && !dateFlag) { … … 200 203 return options; 201 204 } 205 202 206 203 207 -
backend/GlobeGuru-backend/src/main/java/FrontendHandler.java
r1c51912 rcd64b06 130 130 return; 131 131 } 132 133 132 Server.sendResponse(exchange, 200, mapper.writeValueAsString(options)); 134 133 } -
backend/GlobeGuru-backend/src/main/java/ScraperThread.java
r1c51912 rcd64b06 96 96 } else if (optionSet.add(option)) { 97 97 uniqueOptions.add(option); 98 DatabaseUtil.saveOptionToDatabase(option); 98 option.setId(DatabaseUtil.saveOptionToDatabase(option)); 99 scrapeOptionInfo(option); 99 100 System.out.println("Parsed " + option); 100 101 } … … 149 150 150 151 String board = roomOption.select(".rezervacija-objekt").text(); 151 if(board.length() > 2) {152 board = board.substring(0, 2);152 if(board.length() > 2) { 153 board = board.substring(0, 2); 153 154 } 154 if(board.isEmpty() || type.isEmpty()){ 155 continue; 156 } 155 if(board.isEmpty() || type.isEmpty()) continue; 156 157 157 Elements amenityElement = roomOption.select(".objekt-opis"); 158 158 String amenity = (amenityElement != null ? amenityElement.text() : ""); … … 166 166 DatabaseUtil.saveOptionDetails(option.getId(), type,board,amenity, price); 167 167 } 168 } 169 else if(url.contains("booking.escapetravel.mk")){ 170 System.out.println("Scraping info for " + url); 171 172 driver.get(url); 173 try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } //data fetch 174 String pageSource = driver.getPageSource(); 175 Document doc = Jsoup.parse(pageSource); 176 Elements roomOptions = doc.select("#hotel-rooms-container .hotel-room-row"); 177 for(Element roomOption : roomOptions){ 178 String type = roomOption.select("td.align-middle").first().text(); 179 String board = roomOption.select("td.align-middle.text-primary.lead").text(); 180 if (board.isEmpty() || type.isEmpty()) continue; 181 String priceText = roomOption.select("td.align-middle.text-end .text-success.d-block.lead").text().replace("€", "").trim(); 182 float price; 183 if (!priceText.isEmpty()) { 184 price = Float.parseFloat(priceText.replace(",", "")); 185 } else continue; 186 187 Elements amenityElements = doc.select("div.row > div.col-6.col-md-3.col-xl-2"); 188 StringBuilder amenities = new StringBuilder(); 189 for (Element amenityElement : amenityElements) { 190 amenities.append(amenityElement.text()).append(", "); 191 } 192 if (!amenities.isEmpty()) { 193 amenities.setLength(amenities.length() - 2); 194 } 195 System.out.println(type + board + price + amenities); 196 DatabaseUtil.saveOptionDetails(option.getId(), type, board, amenities.toString(), price); 197 } 198 168 199 } 169 200 } -
backend/GlobeGuru-backend/src/main/java/Server.java
r1c51912 rcd64b06 196 196 197 197 public static void sendResponse(HttpExchange exchange, int statusCode, String response) throws IOException { 198 byte[] responseBytes = response.getBytes(StandardCharsets.UTF_8); 198 199 exchange.getResponseHeaders().add("Cross-Origin-Opener-Policy", "unsafe-none"); 199 200 exchange.getResponseHeaders().add("Cross-Origin-Embedder-Policy", "require-corp"); 200 201 exchange.getResponseHeaders().add("Content-Type", "application/json"); 201 exchange.sendResponseHeaders(statusCode, response.length()); 202 exchange.getResponseBody().write(response.getBytes()); 203 exchange.getResponseBody().close(); 204 } 205 202 exchange.getResponseHeaders().add("Transfer-Encoding", "chunked"); 203 exchange.sendResponseHeaders(statusCode, 0); 204 try (OutputStream os = exchange.getResponseBody()) { 205 os.write(responseBytes); 206 } 207 } 206 208 } 207 209 -
backend/GlobeGuru-backend/src/main/resources/URLsJSON.json
r1c51912 rcd64b06 2 2 "agencyurls": 3 3 [ 4 "https://magelantravel.mk/" 5 4 "https://magelantravel.mk/", 5 "https://booking.escapetravel.mk/" 6 6 ] 7 7 } -
backend/GlobeGuru-backend/target/classes/URLsJSON.json
r1c51912 rcd64b06 2 2 "agencyurls": 3 3 [ 4 "https://magelantravel.mk/" 5 4 "https://booking.escapetravel.mk/" 6 5 ] 7 6 } -
backend/GlobeGuru-backend/target/classes/lastUpdateTime.json
r1c51912 rcd64b06 1 1 { 2 "lastUpdateTime" : "2025-01-1 0T18:31:22.019011800"2 "lastUpdateTime" : "2025-01-11T00:07:21.694581100" 3 3 }
Note:
See TracChangeset
for help on using the changeset viewer.