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) {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
String name = "", location = "", description = "", image_url = "";
|
||||
Date start_date = null, end_date = null;
|
||||
try {
|
||||
|
||||
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
|
||||
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 {
|
||||
// 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) {
|
||||
// ignore
|
||||
} 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);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
this.error = R.string.error_scraping;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
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;
|
||||
} else {
|
||||
url = null;
|
||||
event_links = event_links.subList(0, max);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue