Search in sources :

Example 1 with KJV

use of custom.objects.KJV in project bible-online by m0ver.

the class crawler method start.

public void start() throws MalformedURLException {
    try {
        bible bible = new bible();
        bible.setTableName("zh_CN");
        int partId;
        String text;
        URL url;
        URLResourceLoader loader;
        Row o;
        StringBuilder content;
        String words;
        Pattern pat = Pattern.compile("<span class=\"verse\" id=\"(\\d+)\">.*</span>\\s*(.*)(\r\n)*");
        Matcher mat;
        Table list = null;
        for (int i = 1; i <= 66; i++) {
            o = bible.findOne("SELECT max(chapter_id) as n FROM zh_CN WHERE book_id=?", new Object[] { i });
            int n = o.get(0).get("n").intValue();
            url = new URL("https://www.wordplanet.org/kj/b" + (i < 10 ? "0" + i : i) + ".htm");
            loader = new URLResourceLoader(url, true);
            content = loader.getContent();
            int j = 1;
            KJV KJV = new KJV();
            KJV.setBookId(i);
            String defaults = "<h3>Chapter 1</h3>";
            words = content.substring(content.indexOf(defaults) + defaults.length(), content.lastIndexOf("<div class=\"alignRight ym-noprint\">"));
            words = words.replaceAll("<br/>", "\r\n");
            mat = pat.matcher(words);
            while (mat.find()) {
                partId = Integer.parseInt(mat.group(1));
                if (partId == 1) {
                    KJV.setChapterId(j);
                    // Check the chapter id if it's existing in the db.
                    list = KJV.find("SELECT * FROM KJV WHERE book_id = ? and chapter_id = ? order by part_id desc", new Object[] { KJV.getBookId(), KJV.getChapterId() });
                    j++;
                }
                if (null != list && !list.isEmpty() && list.firstElement().getFieldInfo("part_id").intValue() >= partId) {
                    continue;
                }
                KJV kjv = new KJV();
                kjv.setBookId(i);
                kjv.setChapterId(KJV.getChapterId());
                text = mat.group().replaceAll("<span class=\"verse\" id=\"" + partId + "\">" + partId + "</span>\\s*", "");
                kjv.setContent(text);
                kjv.setPartId(partId++);
                kjv.append();
                System.out.println(text);
            }
        }
    } catch (ApplicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Pattern(java.util.regex.Pattern) custom.objects.bible(custom.objects.bible) Table(org.tinystruct.data.component.Table) Matcher(java.util.regex.Matcher) URL(java.net.URL) ApplicationException(org.tinystruct.ApplicationException) URLResourceLoader(org.tinystruct.system.util.URLResourceLoader) KJV(custom.objects.KJV) Row(org.tinystruct.data.component.Row)

Aggregations

KJV (custom.objects.KJV)1 custom.objects.bible (custom.objects.bible)1 URL (java.net.URL)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ApplicationException (org.tinystruct.ApplicationException)1 Row (org.tinystruct.data.component.Row)1 Table (org.tinystruct.data.component.Table)1 URLResourceLoader (org.tinystruct.system.util.URLResourceLoader)1