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 json = document
|
|
||||||
.select("script[type = application/ld+json]")
|
|
||||||
.first().data();
|
|
||||||
|
|
||||||
JSONObject reader = new JSONObject(json);
|
|
||||||
|
|
||||||
|
|
||||||
String name = readFromJson(reader, "name");
|
|
||||||
Date start_date = parseToDate(readFromJson(reader, "startDate"));
|
|
||||||
Date end_date = parseToDate(readFromJson(reader, "endDate"));
|
|
||||||
String description = fixDescriptionLinks(readFromJson(reader, "description"));
|
|
||||||
String location = fixLocation(readFromJson(reader, "location"));
|
|
||||||
|
|
||||||
String image_url = readFromJson(reader, "image"); // get from json
|
|
||||||
|
|
||||||
|
String name = "", location = "", description = "", image_url = "";
|
||||||
|
Date start_date = null, end_date = null;
|
||||||
try {
|
try {
|
||||||
// possibly get higher res image from event header
|
|
||||||
image_url = document.select("div[id=event_header_primary]")
|
|
||||||
.select("img").first().attr("src");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
String json = document
|
||||||
// ignore
|
.select("script[type = application/ld+json]")
|
||||||
|
.first().data();
|
||||||
|
|
||||||
|
JSONObject reader = new JSONObject(json);
|
||||||
|
|
||||||
|
name = readFromJson(reader, "name");
|
||||||
|
start_date = parseToDate(readFromJson(reader, "startDate"));
|
||||||
|
end_date = parseToDate(readFromJson(reader, "endDate"));
|
||||||
|
description = fixDescriptionLinks(readFromJson(reader, "description"));
|
||||||
|
location = fixLocation(readFromJson(reader, "location"));
|
||||||
|
image_url = readFromJson(reader, "image");
|
||||||
|
|
||||||
|
try {
|
||||||
|
image_url = document.select("div[id=event_header_primary]")
|
||||||
|
.select("img").first().attr("src");
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
} 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