diff --git a/src/main/java/org/example/CheckClubKeys.java b/src/main/java/org/example/CheckClubKeys.java new file mode 100644 index 0000000..9449252 --- /dev/null +++ b/src/main/java/org/example/CheckClubKeys.java @@ -0,0 +1,24 @@ +package org.example; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import org.jsoup.Jsoup; +import java.util.List; +import java.util.Map; + +public class CheckClubKeys { + public static void main(String[] args) { + try { + String url = "https://api.afavcd.pt/teams"; + String json = Jsoup.connect(url).ignoreContentType(true).execute().body(); + Gson gson = new Gson(); + List> clubs = gson.fromJson(json, new TypeToken>>() {}.getType()); + if (!clubs.isEmpty()) { + System.out.println("First club keys: " + clubs.get(0).keySet()); + System.out.println("First club data: " + clubs.get(0)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/org/example/StandingsScraper.java b/src/main/java/org/example/StandingsScraper.java index 6c824f1..0af69c1 100644 --- a/src/main/java/org/example/StandingsScraper.java +++ b/src/main/java/org/example/StandingsScraper.java @@ -59,14 +59,29 @@ public class StandingsScraper { }.getType()); for (Map c : dadosClubes) { - if (c.get("teamID") != null) { - int clubId = (int) Double.parseDouble(c.get("teamID").toString()); + Object teamIdObj = c.get("teamID"); + if (teamIdObj == null) teamIdObj = c.get("teamId"); // Fallback para lowercase 'd' + + if (teamIdObj != null) { + int clubId = (int) Double.parseDouble(teamIdObj.toString()); Club club = new Club(); club.setId(clubId); - if (c.get("name") != null) - club.setName(c.get("name").toString()); - if (c.get("logoURL") != null) - club.setImageUrl(c.get("logoURL").toString()); + + // Nomes alternativos + Object name = c.get("name"); + if (name == null) name = c.get("fullName"); + if (name == null) name = c.get("nome"); + + if (name != null) + club.setName(name.toString()); + + // Logo alternativos + Object logo = c.get("logoURL"); + if (logo == null) logo = c.get("logoUrl"); + if (logo == null) logo = c.get("imagem"); + + if (logo != null) + club.setImageUrl(logo.toString()); clubesMap.put(clubId, club); } @@ -135,8 +150,11 @@ public class StandingsScraper { game.setHomeLogo(homeClub != null ? homeClub.getImageUrl() : ""); game.setAwayLogo(awayClub != null ? awayClub.getImageUrl() : ""); - // Tratar Data e Hora (Vem como ISO: 2025-09-20T20:00:00.000Z) - String rawDate = match.get("date") != null ? match.get("date").toString() : ""; + // Tratar Data e Hora + Object dateObj = match.get("date"); + if (dateObj == null) dateObj = match.get("Date"); + + String rawDate = dateObj != null ? dateObj.toString() : ""; if (!rawDate.isEmpty() && rawDate.contains("T")) { String[] parts = rawDate.split("T"); game.setGameDate(parts[0]); // yyyy-MM-dd @@ -148,10 +166,24 @@ public class StandingsScraper { game.setGameHour(""); } - game.setStadium(match.get("field") != null ? match.get("field").toString() : ""); + Object fieldObj = match.get("field"); + if (fieldObj == null) fieldObj = match.get("Field"); + if (fieldObj == null) fieldObj = match.get("campo"); + + game.setStadium(fieldObj != null ? fieldObj.toString() : ""); - String homeGoalsStr = String.valueOf(match.get("homeGoals")); - String awayGoalsStr = String.valueOf(match.get("awayGoals")); + Object reportObj = match.get("reportURL"); + if (reportObj == null) reportObj = match.get("reportUrl"); + + game.setReportUrl(reportObj != null ? reportObj.toString() : ""); + + Object hG = match.get("homeGoals"); + if (hG == null) hG = match.get("home_golos"); + Object aG = match.get("awayGoals"); + if (aG == null) aG = match.get("away_golos"); + + String homeGoalsStr = hG != null ? String.valueOf(hG) : null; + String awayGoalsStr = aG != null ? String.valueOf(aG) : null; if (homeGoalsStr != null && !homeGoalsStr.trim().isEmpty() && !homeGoalsStr.equals("null")) { diff --git a/src/main/java/org/example/models/GameMatch.java b/src/main/java/org/example/models/GameMatch.java index 89533af..0d52e0f 100644 --- a/src/main/java/org/example/models/GameMatch.java +++ b/src/main/java/org/example/models/GameMatch.java @@ -37,6 +37,9 @@ public class GameMatch { @PropertyName("campo") private String stadium; + @PropertyName("report_url") + private String reportUrl; + public GameMatch() { } @@ -149,4 +152,14 @@ public class GameMatch { public void setStadium(String stadium) { this.stadium = stadium; } + + @PropertyName("report_url") + public String getReportUrl() { + return reportUrl; + } + + @PropertyName("report_url") + public void setReportUrl(String reportUrl) { + this.reportUrl = reportUrl; + } }