Legend:
- Unmodified
- Added
- Removed
-
backend/GlobeGuru-backend/src/main/java/ScraperThread.java
r0a7426e rdf7f390 29 29 public class ScraperThread extends Thread { 30 30 private String url; 31 private ConcurrentLinkedQueue<Option> uniqueOptions;32 31 private CountDownLatch latch; 33 private Set<Option> optionSet; 34 35 public ScraperThread(String url, ConcurrentLinkedQueue<Option> optionsQueue, CountDownLatch latch) { 32 33 public ScraperThread(String url, CountDownLatch latch) { 36 34 this.url = url; 37 this.uniqueOptions = optionsQueue;38 35 this.latch = latch; 39 this.optionSet = new HashSet<>();40 36 } 41 37 … … 86 82 for (Element div : childDivs) { 87 83 String data = div.outerHtml(); 88 Option option = optionParser(data, numPeople);84 Option option = optionParser(data, numPeople); 89 85 if (option != null) { 90 Option existingOption = DatabaseUtil.findOption(option); 91 if (existingOption != null) { 92 if (existingOption.equals(option)) { 93 option.setPriceChanged(true); 94 option.setNewPrice(option.getPrice()); 95 } 96 DatabaseUtil.updateOptionInDatabase(option); 97 } else if (optionSet.add(option)) { 98 uniqueOptions.add(option); 99 option.setId(DatabaseUtil.saveOptionToDatabase(option)); 100 scrapeOptionInfo(option); 101 System.out.println("Parsed " + option); 102 } 86 option.setId(DatabaseUtil.saveOptionToDatabase(option)); 87 scrapeOptionInfo(option); 88 System.out.println("Parsed " + option); 103 89 } 104 90 } … … 115 101 for (Element div : childDivs) { 116 102 String data = div.outerHtml(); 117 Option newOption = optionParser(data, numPeople);103 Option newOption = optionParser(data, numPeople); 118 104 if (newOption != null) { 119 if (optionSet.add(newOption)) { 120 uniqueOptions.add(newOption); 121 122 newOption.setId(DatabaseUtil.saveOptionToDatabase(newOption)); 123 scrapeOptionInfo(newOption); 124 System.out.println("Parsed " + newOption); 125 } 126 } 127 } 128 129 } else { 105 newOption.setId(DatabaseUtil.saveOptionToDatabase(newOption)); 106 scrapeOptionInfo(newOption); 107 System.out.println("Parsed " + newOption); 108 } 109 } 110 } else { 130 111 System.out.println("Parent div not found"); 131 112 } … … 134 115 System.out.println("URL not recognized for parsing."); 135 116 } 117 136 118 } 137 119 private void scrapeOptionInfo(Option option) {
Note:
See TracChangeset
for help on using the changeset viewer.