<commit_before>package pl.hypeapp.episodie.dataproviders.crawler;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.hypeapp.core.usecase.episode.extractimdbtoptvshows.GetImdbTopTvShows;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class ImdbTopTvShowsCrawlerDataProvider implements GetImdbTopTvShows {
    private static final int PATH_SECOND_SEGMENT = 2;
    private static final Logger LOGGER = LoggerFactory.getLogger(ImdbTopTvShowsCrawlerDataProvider.class);

    @Override
    public List<String> getImdbIds(String url) {
        System.out.println("CRAWLING");
        try {
            Document document = getDocument(url);
            return initCrawler(document);
        } catch (IOException ex) {
            LOGGER.info("Unable to get document");
            return null;
        }
    }

    private Document getDocument(String url) throws IOException {
        return Jsoup.connect(url).get();
    }

    private List<String> initCrawler(Document document) {
        List<String> imdbTvShowIds = new LinkedList<>();
        for (int i = 1; i <= 100; i++) {
            Elements titleColumn = document.select(".lister-list > tr:nth-child(" + i + ") > td:nth-child(2) > a:nth-child(1)");
            String showUrl = titleColumn.attr("href");
            imdbTvShowIds.add(showUrl.split("/")[PATH_SECOND_SEGMENT]);
        }
        return imdbTvShowIds;
    }
}<commit_msg>Deleted sys out println and collecting up to 125 tv show ids.<commit_after>package pl.hypeapp.episodie.dataproviders.crawler;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.hypeapp.core.usecase.tvshow.toplist.collectimdbtoptvshows.CrawlerFailException;
import pl.hypeapp.core.usecase.tvshow.toplist.collectimdbtoptvshows.GetImdbTopTvShows;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class ImdbTopTvShowsCrawlerDataProvider implements GetImdbTopTvShows {
    private static final int PATH_SECOND_SEGMENT = 2;
    private static final Logger LOGGER = LoggerFactory.getLogger(ImdbTopTvShowsCrawlerDataProvider.class);

    @Override
    public List<String> crawl(String url) {
        Document document;
        try {
            document = getDocument(url);
        } catch (IOException ex) {
            LOGGER.info("Unable to get document");
            throw new CrawlerFailException();
        }
        return initCrawler(document);
    }

    private Document getDocument(String url) throws IOException {
        return Jsoup.connect(url).get();
    }

    private List<String> initCrawler(Document document) {
        List<String> imdbTvShowIds = new LinkedList<>();
        for (int i = 1; i <= 125; i++) {
            Elements titleColumn = document.select(".lister-list > tr:nth-child(" + i + ") > td:nth-child(2) > a:nth-child(1)");
            String showUrl = titleColumn.attr("href");
            imdbTvShowIds.add(showUrl.split("/")[PATH_SECOND_SEGMENT]);
        }
        return imdbTvShowIds;
    }

}
{'fraction_non_alphanumeric': 0.10703173615432483, 'fraction_numerical': 0.006533914125700062, 'mean_word_length': 3.3038821954484603, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6278569', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1032, 'n_words': 202}