Elements eventDivs = doc.select("div.event-page-card");
ListIterator<Element> eventsDivsIter = eventDivs.listIterator();
List<EventSource> eventSources = new ArrayList<EventSource>();
while (eventsDivsIter.hasNext()) {
EventSource eventSource = null;
Element eventDiv = eventsDivsIter.next();
if (eventDiv.select("div.teams").size() != 0) {
// league event
String homeTeam = extractTeam(eventDiv, "div.teams div.home a");
String awayTeam = extractTeam(eventDiv, "div.teams div.away a");
String eventUri = extractTeamEventUri(eventDiv);
if (homeTeam != null && awayTeam != null && eventUri != null) {
eventSource = new EventSource();
eventSource.setEventName(homeTeam + " - " + awayTeam);
eventSource.setEventUri("www.sportowefakty.pl" + eventUri);
}
} else if (eventDiv.select("div.single").size() != 0) {
// single event
Element a = eventDiv.select("div.single a").get(0);
String eventName = a.text();
String eventUri = a.attr("href");
if (eventName != null && eventUri != null) {
eventSource = new EventSource();
eventSource.setEventName(eventName);
eventSource.setEventUri("www.sportowefakty.pl" + eventUri);
}
}
if (eventSource != null) {
String eventGroup = extractEventGroup(eventDiv);
eventSource.setEventGroup(eventGroup);
Date date = extractEventDate(eventDiv);
if (date != null) {
eventSource.setEventDate(DateUtils.truncate(date, Calendar.DAY_OF_MONTH));
eventSource.setEventTime(date);
}
eventSources.add(eventSource);
}
}
return eventSources.size() != 0 ? eventSources : null;