Package net.easymodo.asagi.model

Examples of net.easymodo.asagi.model.Page


        @Override
        @SuppressWarnings("InfiniteLoopStatement")
        public void run() {
            while(true) {
                long startTime = DateTime.now().getMillis();
                Page threadList;
                try {
                    threadList = sourceBoard.getAllThreads(lastMod);
                } catch(HttpGetException e) {
                    if(e.getHttpStatus() == 304)
                        debug(TALK, ("threads.json: not modified"));
                    else
                        debug(WARN, "threads.json: " + e.getMessage());
                    sleepRemaining(startTime);
                    continue;
                } catch(ContentGetException e) {
                    debug(WARN, "Error getting thread list: " + e.getMessage());
                    sleepRemaining(startTime);
                    continue;
                } catch(ContentParseException e) {
                    debug(WARN, "Error parsing thread list: " + e.getMessage());
                    sleepRemaining(startTime);
                    continue;
                }

                lastMod = threadList.getLastMod();

                Map<Integer,Topic> threadMap = new HashMap<Integer, Topic>();
                for(Topic topic : threadList.getThreads()) {
                    threadMap.put(topic.getNum(), topic);
                }

                // Go over the old threads
                for(Topic oldTopic : topics.values()) {
View Full Code Here


    public Page getPage(int pageNum, String lastMod) throws ContentGetException, ContentParseException {
        String[] wgetReply = this.wgetText(this.linkPage(pageNum), lastMod);
        String pageText = wgetReply[0];
        String newLastMod = wgetReply[1];

        Page p = new Page(pageNum);
        Topic t = null;

        Matcher mat = postGetPattern.matcher(pageText);

        while(mat.find()) {
            String text = mat.group(1);
            String type = mat.group(2);

            if(type.equals("opContainer")) {
                t = this.parseThread(text);
                p.addThread(t);
            } else {
                if(t != null) t.addPost(this.parsePost(text, t.getNum()));
            }
        }

        p.setLastMod(newLastMod);
        return p;
    }
View Full Code Here

            pageJson = GSON.fromJson(pageText, PageJson.class);
        } catch(JsonSyntaxException ex) {
            throw new ContentGetException("API returned invalid JSON", ex);
        }

        Page p = new Page(pageNum);
        Topic t = null;

        for(TopicJson tj : pageJson.getThreads()) {
            for(PostJson pj : tj.getPosts()) {
                if(pj.getResto() == 0) {
                    t = this.makeThreadFromJson(pj);
                    p.addThread(t);
                } else {
                    if(t != null) t.addPost(this.makePostFromJson(pj));
                }
            }
        }

        p.setLastMod(newLastMod);
        return p;
    }
View Full Code Here

    public Page getAllThreads(String lastMod) throws ContentGetException, ContentParseException {
        String[] wgetReply = this.wgetText(this.linkThreads(), lastMod);
        String threadsText = wgetReply[0];
        String newLastMod = wgetReply[1];

        Page threadList = new Page(-1);
        threadList.setLastMod(newLastMod);

        TopicListJson.Page[] topicsJson;
        try {
            topicsJson = GSON.fromJson(threadsText, TopicListJson.Page[].class);
        } catch(JsonSyntaxException ex) {
            throw new ContentGetException("API returned invalid JSON", ex);
        }

        if(topicsJson == null) {
            throw new ContentParseException("API returned empty JSON in threads.json");
        }

        for(TopicListJson.Page page : topicsJson) {
            for(TopicListJson.Topic topic : page.getThreads()) {
                Topic t = new Topic(topic.getNo(), 0, 0);
                t.setLastModTimestamp(topic.getLastModified());
                t.setLastPage(page.getPage());
                threadList.addThread(t);
            }
        }

        return threadList;
    }
View Full Code Here

        public void run() {
            while(true) {
                long startTime = DateTime.now().getMillis();
                for(int pageNo : pageNos) {
                    String lastMod = pagesLastMods[pageNo];
                    Page page;

                    long pageStartTime = DateTime.now().getMillis();

                    try {
                        page = sourceBoard.getPage(pageNo, lastMod);
                    } catch(HttpGetException e) {
                        if(e.getHttpStatus() == 304)
                            debug(TALK, (pageNo == 0 ? "front page" : "page " + pageNo)
                                    + ": wasn't modified");
                        else
                            debug(WARN, "page " + pageNo + ": " + e.getMessage());
                        continue;
                    } catch(ContentGetException e) {
                        debug(WARN, "page " + pageNo + ": " + e.getMessage());
                        continue;
                    } catch(ContentParseException e) {
                        debug(WARN, "page " + pageNo + ": " + e.getMessage());
                        continue;
                    }

                    if(page == null) {
                        debug(WARN, (pageNo == 0 ? "front page" : "page " + pageNo)
                                + "had no threads");
                        continue;
                    }

                    pagesLastMods[pageNo] = page.getLastMod();

                    debug(INFO, "got page " + pageNo);

                    for(Topic newTopic : page.getThreads()) {
                        int num = newTopic.getNum();

                        // If we never saw this topic, then we'll put it in the
                        // new topics queue, a TopicFetcher will take care of
                        // it.
View Full Code Here

TOP

Related Classes of net.easymodo.asagi.model.Page

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.