chapter_006/src/main/java/ru/job4j/parser/Downloader.java
/**
     * Download offers depending on the date.
     *
     * @param newTable - was create table or not.
     * @return - List of offers.
     */
Download offers depending on the date.
@param newTable - was create table or not.
@return - List of offers.
Download offers depending on the date . @param newTable - was create table or not . @return - List of offers .
public List<Offer> download(Boolean newTable) {
        LOGGER.info("--------START DOWNLOAD OFFERS FROM WEBSITE--------");
        List<Offer> result = new ArrayList<>();
        Calendar startDate = Calendar.getInstance();
        if (newTable) {
            startDate.set(Calendar.DAY_OF_MONTH, 1);
            startDate.set(Calendar.MONTH, Calendar.JANUARY);
        } else {
            startDate.add(Calendar.WEEK_OF_YEAR, -1);
        }
        Calendar finalDate = Calendar.getInstance();
        while (startDate.getTimeInMillis() <= finalDate.getTimeInMillis() || this.url.equals(this.newURL)) {
            connect();
            for (Element el : this.elements) {
                String element = el.select("td.postslisttopic").text().toLowerCase();
                if ((element.contains("java") && !element.contains("script") && (element.contains("вакансия") || element.contains("работа") || element.contains("нужен")))) {
                    String url = el.select("td.postslisttopic > a[href]").attr("href");
                    String data = el.select("td").get(5).text();
                    finalDate = correctDate(data);
                    result.add(new Offer(element, url, new Timestamp(finalDate.getTimeInMillis())));
                }
            }
            this.newURL = String.format("%s/%s", this.url, step++);
        }
        LOGGER.info("--------FINISH DOWNLOAD OFFERS FROM WEBSITE--------");
        return result;
    }
public List < Offer > download ( Boolean newTable ) { LOGGER . info ( "--------START DOWNLOAD OFFERS FROM WEBSITE--------" ) ; List < Offer > result = new ArrayList < > ( ) ; Calendar startDate = Calendar . getInstance ( ) ; if ( newTable ) { startDate . set ( Calendar . DAY_OF_MONTH , 1 ) ; startDate . set ( Calendar . MONTH , Calendar . JANUARY ) ; } else { startDate . add ( Calendar . WEEK_OF_YEAR , - 1 ) ; } Calendar finalDate = Calendar . getInstance ( ) ; while ( startDate . getTimeInMillis ( ) <= finalDate . getTimeInMillis ( ) || this . url . equals ( this . newURL ) ) { connect ( ) ; for ( Element el : this . elements ) { String element = el . select ( "td.postslisttopic" ) . text ( ) . toLowerCase ( ) ; if ( ( element . contains ( "java" ) && ! element . contains ( "script" ) && ( element . contains ( "вакансия") || ele m nt contain s ("работа " ) || element.c o ta ns("нуж е н")))) { String url = el . select ( "td.postslisttopic > a[href]" ) . attr ( "href" ) ; String data = el . select ( "td" ) . get ( 5 ) . text ( ) ; finalDate = correctDate ( data ) ; result . add ( new Offer ( element , url , new Timestamp ( finalDate . getTimeInMillis ( ) ) ) ) ; } } this . newURL = String . format ( "%s/%s" , this . url , step ++ ) ; } LOGGER . info ( "--------FINISH DOWNLOAD OFFERS FROM WEBSITE--------" ) ; return result ; }
Download offers depending on the date.
Download offers depending on the date .