Search in sources :

Example 1 with Question

use of io.github.izzyleung.zhihudailypurify.bean.Question in project ZhihuDailyPurify by izzyleung.

the class NewsListFromZhihuObservable method getQuestions.

private static List<Question> getQuestions(Document document, String dailyTitle) {
    List<Question> result = new ArrayList<>();
    Elements questionElements = getQuestionElements(document);
    for (Element questionElement : questionElements) {
        Question question = new Question();
        String questionTitle = getQuestionTitleFromQuestionElement(questionElement);
        String questionUrl = getQuestionUrlFromQuestionElement(questionElement);
        // Make sure that the question's title is not empty.
        questionTitle = TextUtils.isEmpty(questionTitle) ? dailyTitle : questionTitle;
        question.setTitle(questionTitle);
        question.setUrl(questionUrl);
        result.add(question);
    }
    return result;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Question(io.github.izzyleung.zhihudailypurify.bean.Question) Elements(org.jsoup.select.Elements)

Example 2 with Question

use of io.github.izzyleung.zhihudailypurify.bean.Question in project ZhihuDailyPurify by izzyleung.

the class NewsListFromZhihuObservable method convertToDailyNews.

private static Optional<DailyNews> convertToDailyNews(Pair<Story, Document> pair) {
    DailyNews result = null;
    Story story = pair.first;
    Document document = pair.second;
    String dailyTitle = story.getDailyTitle();
    List<Question> questions = getQuestions(document, dailyTitle);
    if (Stream.of(questions).allMatch(Question::isValidZhihuQuestion)) {
        result = new DailyNews();
        result.setDailyTitle(dailyTitle);
        result.setThumbnailUrl(story.getThumbnailUrl());
        result.setQuestions(questions);
    }
    return Optional.ofNullable(result);
}
Also used : Question(io.github.izzyleung.zhihudailypurify.bean.Question) DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews) Document(org.jsoup.nodes.Document) Story(io.github.izzyleung.zhihudailypurify.bean.Story)

Aggregations

Question (io.github.izzyleung.zhihudailypurify.bean.Question)2 DailyNews (io.github.izzyleung.zhihudailypurify.bean.DailyNews)1 Story (io.github.izzyleung.zhihudailypurify.bean.Story)1 ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1