feat: add support for alternative JSON keys in scraper and introduce report URL field to GameMatch model
This commit is contained in:
24
src/main/java/org/example/CheckClubKeys.java
Normal file
24
src/main/java/org/example/CheckClubKeys.java
Normal file
@@ -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<Map<String, Object>> clubs = gson.fromJson(json, new TypeToken<List<Map<String, Object>>>() {}.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,14 +59,29 @@ public class StandingsScraper {
|
|||||||
}.getType());
|
}.getType());
|
||||||
|
|
||||||
for (Map<String, Object> c : dadosClubes) {
|
for (Map<String, Object> c : dadosClubes) {
|
||||||
if (c.get("teamID") != null) {
|
Object teamIdObj = c.get("teamID");
|
||||||
int clubId = (int) Double.parseDouble(c.get("teamID").toString());
|
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 club = new Club();
|
||||||
club.setId(clubId);
|
club.setId(clubId);
|
||||||
if (c.get("name") != null)
|
|
||||||
club.setName(c.get("name").toString());
|
// Nomes alternativos
|
||||||
if (c.get("logoURL") != null)
|
Object name = c.get("name");
|
||||||
club.setImageUrl(c.get("logoURL").toString());
|
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);
|
clubesMap.put(clubId, club);
|
||||||
}
|
}
|
||||||
@@ -135,8 +150,11 @@ public class StandingsScraper {
|
|||||||
game.setHomeLogo(homeClub != null ? homeClub.getImageUrl() : "");
|
game.setHomeLogo(homeClub != null ? homeClub.getImageUrl() : "");
|
||||||
game.setAwayLogo(awayClub != null ? awayClub.getImageUrl() : "");
|
game.setAwayLogo(awayClub != null ? awayClub.getImageUrl() : "");
|
||||||
|
|
||||||
// Tratar Data e Hora (Vem como ISO: 2025-09-20T20:00:00.000Z)
|
// Tratar Data e Hora
|
||||||
String rawDate = match.get("date") != null ? match.get("date").toString() : "";
|
Object dateObj = match.get("date");
|
||||||
|
if (dateObj == null) dateObj = match.get("Date");
|
||||||
|
|
||||||
|
String rawDate = dateObj != null ? dateObj.toString() : "";
|
||||||
if (!rawDate.isEmpty() && rawDate.contains("T")) {
|
if (!rawDate.isEmpty() && rawDate.contains("T")) {
|
||||||
String[] parts = rawDate.split("T");
|
String[] parts = rawDate.split("T");
|
||||||
game.setGameDate(parts[0]); // yyyy-MM-dd
|
game.setGameDate(parts[0]); // yyyy-MM-dd
|
||||||
@@ -148,10 +166,24 @@ public class StandingsScraper {
|
|||||||
game.setGameHour("");
|
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");
|
||||||
|
|
||||||
String homeGoalsStr = String.valueOf(match.get("homeGoals"));
|
game.setStadium(fieldObj != null ? fieldObj.toString() : "");
|
||||||
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()
|
if (homeGoalsStr != null && !homeGoalsStr.trim().isEmpty()
|
||||||
&& !homeGoalsStr.equals("null")) {
|
&& !homeGoalsStr.equals("null")) {
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class GameMatch {
|
|||||||
@PropertyName("campo")
|
@PropertyName("campo")
|
||||||
private String stadium;
|
private String stadium;
|
||||||
|
|
||||||
|
@PropertyName("report_url")
|
||||||
|
private String reportUrl;
|
||||||
|
|
||||||
public GameMatch() {
|
public GameMatch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,4 +152,14 @@ public class GameMatch {
|
|||||||
public void setStadium(String stadium) {
|
public void setStadium(String stadium) {
|
||||||
this.stadium = stadium;
|
this.stadium = stadium;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PropertyName("report_url")
|
||||||
|
public String getReportUrl() {
|
||||||
|
return reportUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PropertyName("report_url")
|
||||||
|
public void setReportUrl(String reportUrl) {
|
||||||
|
this.reportUrl = reportUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user