예제 #1
0
  private List<CuriositySegment> parseSegments(Element element) {
    List<CuriositySegment> segments = Lists.newArrayList();
    DateTime flightDate = new DateTime();
    Elements segmentElements = element.select("tbody>tr");
    for (Element segmentElement : segmentElements) {
      if (!segmentElement.select("td.upsellCity").text().equalsIgnoreCase("")
          && segmentElement.select("td.upsellCity").text() != null) {
        CuriositySegment segment = new CuriositySegment();
        String airlineCode = segmentElement.select("td[id~=idUpsellIti]").text();
        String depCode = segmentElement.select("td.upsellCity").get(0).text();
        String arrCode = segmentElement.select("td.upsellCity").get(1).text();
        String depTime = segmentElement.select("td.upsellTime").get(0).text();
        String arrTime = segmentElement.select("td.upsellTime").get(1).text();
        segment.setDepartureName(depCode);
        segment.setArrivalName(arrCode);

        if (depTime.contains("+")) {
          flightDate =
              flightDate.plusDays(
                  Integer.parseInt(
                      depTime.substring(depTime.indexOf("+") + 1, depTime.indexOf("+") + 2)));
          depTime = depTime.substring(0, (depTime.indexOf("+") - 1));
        }
        segment.setDepartureTime(
            PARSER_DATE_TIME_FORMATTER, DATE_TIME_FORMATTER.print(flightDate) + depTime);
        if (arrTime.contains("+")) {
          flightDate =
              flightDate.plusDays(
                  Integer.parseInt(
                      arrTime.substring(arrTime.indexOf("+") + 1, arrTime.indexOf("+") + 2)));
          arrTime = arrTime.substring(0, (arrTime.indexOf("+") - 1));
        }

        segment.setArrivalTime(
            PARSER_DATE_TIME_FORMATTER, DATE_TIME_FORMATTER.print(flightDate) + arrTime);
        segment.setAirlineCode(airlineCode.substring(0, 2));
        segment.setFlightNumber(airlineCode.substring(2));
        segments.add(segment);
      }
    }
    return segments;
  }
예제 #2
0
  public static void main(String[] args) throws Exception {
    VietnamAirlinesFlight vietnamFlight = new VietnamAirlinesFlight();
    CuriositySearch search = new CuriositySearch();
    search.setDepartureCode("HAN");
    search.setArrivalCode("SGN");
    search.setOutboundDate(DATE_FORMATTER.parseDateTime("2015-04-17"));
    //		search.setInboundDate(DATE_FORMATTER.parseDateTime("2013-12-30"));
    search.setAdultsCount(1);
    search.setChildrenCount(0);
    search.setInfantsCount(0);
    // search.setInboundDate(DATE_FORMATTER.parseDateTime("2015-01-10"));
    List<CuriosityFare> fares = vietnamFlight.getFare(search);
    System.err.println("Load data");
    for (CuriosityFare fare : fares) {
      System.err.println("Price " + fare.getPrice());
      System.err.println("Adult Price " + fare.getPricePerAdult());
      System.err.println("Children Price " + fare.getPricePerChild());
      System.err.println("Currency " + fare.getCurrencyCode());
      if (fare.getInboundSegments() != null) {
        for (CuriositySegment segment : fare.getOutboundSegments()) {
          System.err.println(
              segment.getAirlineCode()
                  + " "
                  + segment.getFlightNumber()
                  + " "
                  + segment.getDepartureCode()
                  + " "
                  + segment.getArrivalCode()
                  + " "
                  + segment.getDepartureTime()
                  + " - "
                  + segment.getArrivalTime());
        }
        for (CuriositySegment segment : fare.getInboundSegments()) {
          System.err.println(
              segment.getAirlineCode()
                  + " "
                  + segment.getFlightNumber()
                  + " "
                  + segment.getDepartureCode()
                  + " "
                  + segment.getArrivalCode()
                  + " "
                  + segment.getDepartureTime()
                  + " - "
                  + segment.getArrivalTime());
        }

      } else {
        for (CuriositySegment segment : fare.getOutboundSegments()) {
          System.err.println(
              segment.getAirlineCode()
                  + " "
                  + segment.getFlightNumber()
                  + " "
                  + segment.getDepartureCode()
                  + " "
                  + segment.getArrivalCode()
                  + " "
                  + segment.getDepartureTime()
                  + " - "
                  + segment.getArrivalTime());
        }
      }
    }
  }