git://git.nikiroo.be
/
gofetch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Separate story details components
[gofetch.git]
/
src
/
be
/
nikiroo
/
gofetch
/
support
/
LWN.java
diff --git
a/src/be/nikiroo/gofetch/support/LWN.java
b/src/be/nikiroo/gofetch/support/LWN.java
index dba4c3bfa922f684729352baa2d438e075c1ac88..37a5a8f2fefcf8a88b71228e3ee62db01b88a86a 100644
(file)
--- a/
src/be/nikiroo/gofetch/support/LWN.java
+++ b/
src/be/nikiroo/gofetch/support/LWN.java
@@
-31,12
+31,12
@@
public class LWN extends BasicSupport {
List<Story> list = new ArrayList<Story>();
URL url = new URL("https://lwn.net/");
List<Story> list = new ArrayList<Story>();
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());
Document doc = DataUtil.load(in, "UTF-8", url.toString());
- Elements
stori
es = doc.getElementsByClass("pure-u-1");
- for (Element
story : stori
es) {
- Elements titles =
story
.getElementsByClass("Headline");
- Elements listings =
story
.getElementsByClass("BlurbListing");
+ Elements
articl
es = doc.getElementsByClass("pure-u-1");
+ for (Element
article : articl
es) {
+ Elements titles =
article
.getElementsByClass("Headline");
+ Elements listings =
article
.getElementsByClass("BlurbListing");
if (titles.size() == 0) {
continue;
}
if (titles.size() == 0) {
continue;
}
@@
-59,8
+59,16
@@
public class LWN extends BasicSupport {
}
body = body.trim();
}
body = body.trim();
+ int pos;
+
+ String categ = "";
+ pos = details.indexOf("]");
+ if (pos >= 0) {
+ categ = details.substring(1, pos + 1).trim();
+ }
+
String author = "";
String author = "";
-
int
pos = details.indexOf(" by ");
+ pos = details.indexOf(" by ");
if (pos >= 0) {
author = details.substring(pos + " by ".length()).trim();
}
if (pos >= 0) {
author = details.substring(pos + " by ".length()).trim();
}
@@
-69,12
+77,19
@@
public class LWN extends BasicSupport {
pos = details.indexOf(" Posted ");
if (pos >= 0) {
date = details.substring(pos + " Posted ".length()).trim();
pos = details.indexOf(" Posted ");
if (pos >= 0) {
date = details.substring(pos + " Posted ".length()).trim();
+ pos = details.indexOf(" by ");
+ if (pos >= 0) {
+ author = details.substring(0, pos).trim();
+ }
}
}
+ // We extracted everything from details so...
+ details = "";
+
String id = "";
String intUrl = "";
String extUrl = "";
String id = "";
String intUrl = "";
String extUrl = "";
- for (Element idElem :
story
.getElementsByTag("a")) {
+ for (Element idElem :
article
.getElementsByTag("a")) {
// Last link is the story link
intUrl = idElem.absUrl("href");
pos = intUrl.indexOf("#Comments");
// Last link is the story link
intUrl = idElem.absUrl("href");
pos = intUrl.indexOf("#Comments");
@@
-84,8
+99,8
@@
public class LWN extends BasicSupport {
id = intUrl.replaceAll("[^0-9]", "");
}
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;
}
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());
// 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");
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<String> toLines(Element element) {
}
private List<String> toLines(Element element) {
- return toLines(element, new
Quote
Processor() {
+ return toLines(element, new
BasicElement
Processor() {
@Override
public String processText(String text) {
while (text.startsWith(">")) { // comments
@Override
public String processText(String text) {
while (text.startsWith(">")) { // comments