Ejemplo n.º 1
0
  /**
   * not very nice .. code duplicate and exit not nice
   *
   * @param range
   */
  public void loaderFrom(int range) {

    int numPage;
    boolean retry = false;
    for (StockGeneral g : CacheStockGeneral.getIsinCache().values()) {
      Consensus cnote = ConsensusParserInvestir.fetchStock(g.getCode());

      String url = startUrl + getPlace(g.getPlace()) + midUrl + g.getRealCodif() + endUrl + 0;

      try {
        String text;
        int loopPage = 0;

        // inifinite loop
        do {
          text = ParserCommon.loadUrl(new URL(url));
          if (text == null) retry = true;
          else retry = false;
        } while (retry);

        Document doc = Jsoup.parse(text);
        BatchPoints bp = InfluxDaoConnector.getBatchPoints(StockHistory.dbName);

        Elements links = doc.select(refCode);
        int count = 0;

        for (Element link : links) {

          if (link.children().size() > 40) {
            Elements sublinks = link.children().select("tr");
            for (Element elt : sublinks) {
              Elements t = elt.select("td");
              if (t.size() > 3) {
                loopPage++;
                StockHistory hist = new StockHistory(g);
                hist.setDayGoogle(t.get(0).text());

                hist.setOpening(
                    new Double(
                        t.get(1).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setHighest(
                    new Double(
                        t.get(2).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setLowest(
                    new Double(
                        t.get(3).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setValue(
                    new Double(
                        t.get(4).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setVolume(
                    new Double(
                        t.get(5).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setConsensusNote(cnote.getNotation(cnote.getIndice(loopPage + 0)).getAvg());

                HistoryParser.saveHistory(bp, hist);
                System.out.println(hist.toString());
                if (++count >= range) break;
              }
            }
          }
        }
        InfluxDaoConnector.writePoints(bp);

      } catch (IOException e) {
        e.printStackTrace();
        System.out.println("ERROR for : " + g.getName());
      }
    }
  }
Ejemplo n.º 2
0
  public void loaderSpecific(StockGeneral g) {

    int numPage;
    boolean retry;
    String startUrl = "http://www.google.com/finance/historical?q=FRA%3A";

    Consensus cnote = ConsensusParserInvestir.fetchStock(g.getCode());
    for (numPage = 0; numPage <= MAXPAGE; numPage += PAGINATION) {
      String url = startUrl + g.getCodif() + endUrl + numPage;
      try {
        String text;
        int loopPage = 0;

        // inifinite loop
        do {
          text = ParserCommon.loadUrl(new URL(url));
          if (text == null) retry = true;
          else retry = false;
        } while (retry);

        Document doc = Jsoup.parse(text);
        BatchPoints bp = InfluxDaoConnector.getBatchPoints(StockHistory.dbName);

        Elements links = doc.select(refCode);

        for (Element link : links) {

          if (link.children().size() > 40) {
            Elements sublinks = link.children().select("tr");
            for (Element elt : sublinks) {
              Elements t = elt.select("td");
              if (t.size() > 3) {
                loopPage++;
                StockHistory hist = new StockHistory(g);
                hist.setDayGoogle(t.get(0).text());

                hist.setOpening(
                    new Double(
                        t.get(1).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setHighest(
                    new Double(
                        t.get(2).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setLowest(
                    new Double(
                        t.get(3).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setValue(
                    new Double(
                        t.get(4).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setVolume(
                    new Double(
                        t.get(5).text().replaceAll(" ", "").replace(",", "").replace("-", "0")));
                hist.setConsensusNote(
                    cnote.getNotation(cnote.getIndice(loopPage + numPage)).getAvg());

                HistoryParser.saveHistory(bp, hist); // dont save no trading day
                System.out.println(hist.toString());
              }
            }
          }
        }
        InfluxDaoConnector.writePoints(bp);

      } catch (IOException e) {
        e.printStackTrace();
        System.out.println("ERROR for : " + g.getName());
      }
    }
  }