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();
}
}
Aggregations