display event image and title even on failure
This commit is contained in:
parent
43913ccd21
commit
f579094cec
|
@ -152,35 +152,44 @@ public class FbEventScraper extends AsyncTask<Void, Void, Void> {
|
||||||
if (document == null) {
|
if (document == null) {
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String name = "", location = "", description = "", image_url = "";
|
||||||
|
Date start_date = null, end_date = null;
|
||||||
|
try {
|
||||||
|
|
||||||
String json = document
|
String json = document
|
||||||
.select("script[type = application/ld+json]")
|
.select("script[type = application/ld+json]")
|
||||||
.first().data();
|
.first().data();
|
||||||
|
|
||||||
JSONObject reader = new JSONObject(json);
|
JSONObject reader = new JSONObject(json);
|
||||||
|
|
||||||
|
name = readFromJson(reader, "name");
|
||||||
String name = readFromJson(reader, "name");
|
start_date = parseToDate(readFromJson(reader, "startDate"));
|
||||||
Date start_date = parseToDate(readFromJson(reader, "startDate"));
|
end_date = parseToDate(readFromJson(reader, "endDate"));
|
||||||
Date end_date = parseToDate(readFromJson(reader, "endDate"));
|
description = fixDescriptionLinks(readFromJson(reader, "description"));
|
||||||
String description = fixDescriptionLinks(readFromJson(reader, "description"));
|
location = fixLocation(readFromJson(reader, "location"));
|
||||||
String location = fixLocation(readFromJson(reader, "location"));
|
image_url = readFromJson(reader, "image");
|
||||||
|
|
||||||
String image_url = readFromJson(reader, "image"); // get from json
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// possibly get higher res image from event header
|
|
||||||
image_url = document.select("div[id=event_header_primary]")
|
image_url = document.select("div[id=event_header_primary]")
|
||||||
.select("img").first().attr("src");
|
.select("img").first().attr("src");
|
||||||
|
} catch (Exception ignored) {
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (JSONException | NullPointerException e) {
|
||||||
|
name = document.title();
|
||||||
|
try {
|
||||||
|
image_url = document.select("div[id*=event_header]")
|
||||||
|
.select("img").first().attr("src");
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.event = new FbEvent(url, name, start_date, end_date, description, location, image_url);
|
this.event = new FbEvent(url, name, start_date, end_date, description, location, image_url);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
this.error = R.string.error_scraping;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.error = R.string.error_connection;
|
this.error = R.string.error_connection;
|
||||||
|
|
|
@ -81,6 +81,7 @@ public class FbPageScraper extends AsyncTask<Void, Void, Void> {
|
||||||
this.url = "https://mbasic.facebook.com" + next_url;
|
this.url = "https://mbasic.facebook.com" + next_url;
|
||||||
} else {
|
} else {
|
||||||
url = null;
|
url = null;
|
||||||
|
event_links = event_links.subList(0, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue