X-Git-Url: https://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FLWN.java;h=c033104f92fed7e7a81a5673894c0463a8d0608e;hb=a81f396bc4bf0f70e4b5f654045f533941d86dc9;hp=c492d10d21cde68e48f1390db8efcf7b0a10c470;hpb=100a839503d23e324d2db3f6d3e47892def3bf81;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/support/LWN.java b/src/be/nikiroo/gofetch/support/LWN.java index c492d10..c033104 100644 --- a/src/be/nikiroo/gofetch/support/LWN.java +++ b/src/be/nikiroo/gofetch/support/LWN.java @@ -31,7 +31,7 @@ public class LWN extends BasicSupport { List list = new ArrayList(); URL url = new URL("https://lwn.net/"); - InputStream in = open(url); + InputStream in = downloader.open(url); Document doc = DataUtil.load(in, "UTF-8", url.toString()); Elements articles = doc.getElementsByClass("pure-u-1"); for (Element article : articles) { @@ -59,8 +59,16 @@ public class LWN extends BasicSupport { } body = body.trim(); + int pos; + + String categ = ""; + pos = details.indexOf("]"); + if (pos >= 0) { + categ = details.substring(1, pos).trim(); + } + String author = ""; - int pos = details.indexOf(" by "); + pos = details.indexOf(" by "); if (pos >= 0) { author = details.substring(pos + " by ".length()).trim(); } @@ -69,8 +77,15 @@ public class LWN extends BasicSupport { pos = details.indexOf(" Posted "); if (pos >= 0) { date = details.substring(pos + " Posted ".length()).trim(); + pos = date.indexOf(" by "); + if (pos >= 0) { + date = date.substring(0, pos).trim(); + } } + // We extracted everything from details so... + details = ""; + String id = ""; String intUrl = ""; String extUrl = ""; @@ -84,8 +99,8 @@ public class LWN extends BasicSupport { id = intUrl.replaceAll("[^0-9]", ""); } - list.add(new Story(getType(), id, title, details, intUrl, extUrl, - body)); + list.add(new Story(getType(), id, title, author, date, categ, + details, intUrl, extUrl, body)); } return list; @@ -99,7 +114,7 @@ public class LWN extends BasicSupport { // Do not try the paid-for stories... if (!story.getTitle().startsWith("[$]")) { URL url = new URL(story.getUrlInternal()); - InputStream in = open(url); + InputStream in = downloader.open(url); Document doc = DataUtil.load(in, "UTF-8", url.toString()); Elements fullContentElements = doc .getElementsByClass("ArticleText"); @@ -167,7 +182,7 @@ public class LWN extends BasicSupport { } private List toLines(Element element) { - return toLines(element, new QuoteProcessor() { + return toLines(element, new BasicElementProcessor() { @Override public String processText(String text) { while (text.startsWith(">")) { // comments @@ -201,11 +216,6 @@ public class LWN extends BasicSupport { return false; } - - @Override - public String manualProcessing(Node node) { - return null; - } }); } }