Compare commits
5 Commits
main
...
recuperado
| Author | SHA1 | Date | |
|---|---|---|---|
| da558c5a90 | |||
| cbdaa8a5e5 | |||
| 02a235c114 | |||
| 18658058de | |||
| a7bd44ba18 |
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
testeScraper
|
||||
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1 +0,0 @@
|
||||
{"14":[{"season":"2025/2026","jorneyID":2317,"numberJorney":"14","Home":22,"Away":19,"homeGoals":"11","awayGoals":"1","cup":0,"date":"2026-04-17T20:00:00.000Z","field":"Touguinha","reportURL":"/uploads/reports/33/3/2317.pdf","typeModality":"Junior"},{"season":"2025/2026","jorneyID":2319,"numberJorney":"14","Home":13,"Away":11,"homeGoals":"2","awayGoals":"8","cup":0,"date":"2026-04-19T09:00:00.000Z","field":"Arcos","reportURL":"/uploads/reports/33/3/2319.pdf","typeModality":"Junior"},{"season":"2025/2026","jorneyID":2321,"numberJorney":"14","Home":6,"Away":-1,"homeGoals":"","awayGoals":"","cup":0,"date":"1970-01-01T00:00:00.000Z","field":"Aveleda F.C.","reportURL":null,"typeModality":"Junior"},{"season":"2025/2026","jorneyID":2318,"numberJorney":"14","Home":2,"Away":12,"homeGoals":"11","awayGoals":"0","cup":0,"date":"2026-04-17T20:00:00.000Z","field":"Bagunte","reportURL":null,"typeModality":"Junior"},{"season":"2025/2026","jorneyID":2320,"numberJorney":"14","Home":23,"Away":25,"homeGoals":"7","awayGoals":"3","cup":0,"date":"2026-04-17T20:00:00.000Z","field":"Rio Mau","reportURL":"/uploads/reports/33/3/2320.pdf","typeModality":"Junior"}]}
|
||||
@@ -1,38 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class ApiDiscoveryCombinations {
|
||||
public static void main(String[] args) {
|
||||
String[] paths = {
|
||||
"https://api.afavcd.pt/jorney/season/33/modality/1/discipline/teams",
|
||||
"https://api.afavcd.pt/jorney/modality/1/season/33/discipline/teams",
|
||||
"https://api.afavcd.pt/jorney/season/33/modality/1/discipline/1",
|
||||
"https://api.afavcd.pt/jorney/season/33/modality/1/discipline/1/1",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/discipline/1/jorney/1",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/discipline/teams/jorney/1",
|
||||
"https://api.afavcd.pt/standings/season/33/modality/1/discipline/1",
|
||||
"https://api.afavcd.pt/standings/season/33/modality/1/discipline/teams"
|
||||
};
|
||||
|
||||
for (String url : paths) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Result: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class ApiExplorer {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/modalities",
|
||||
"https://api.afavcd.pt/seasons/33/modalities",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/levels"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Exploring: " + url);
|
||||
try {
|
||||
String body = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
System.out.println("Result: " + body);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class BruteForceJorneyIds {
|
||||
public static void main(String[] args) {
|
||||
// We know 2166 is Journey 31 for Senior (Modality 1)
|
||||
// Let's test a range of IDs
|
||||
for (int id = 2130; id <= 2170; id++) {
|
||||
String url = "https://api.afavcd.pt/seasons/33/teams/modality/1/jorney?jorneyID=" + id;
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.timeout(2000)
|
||||
.execute();
|
||||
if (response.statusCode() == 200) {
|
||||
String body = response.body();
|
||||
// Check if the body contains the ID we asked for
|
||||
if (body.contains(String.valueOf(id))) {
|
||||
System.out.println("ID " + id + " is valid and returned data.");
|
||||
} else {
|
||||
// System.out.println("ID " + id + " returned journey 31 data instead.");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("ID " + id + " failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class ChampionshipExplorer {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/championships",
|
||||
"https://api.afavcd.pt/seasons/33/championships",
|
||||
"https://api.afavcd.pt/championship/1/standings",
|
||||
"https://api.afavcd.pt/championship/1/jorney"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class ChampionshipJorneysTest {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/championship/1/jorneys",
|
||||
"https://api.afavcd.pt/championship/1/jorneys/1",
|
||||
"https://api.afavcd.pt/championship/3/jorneys",
|
||||
"https://api.afavcd.pt/championship/1/standings"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class CheckSeasons {
|
||||
public static void main(String[] args) {
|
||||
String url = "https://api.afavcd.pt/seasons";
|
||||
try {
|
||||
String body = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
System.out.println("Seasons JSON: " + body);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
153
src/main/java/org/example/CupScraper.java
Normal file
153
src/main/java/org/example/CupScraper.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package org.example;
|
||||
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.FirebaseOptions;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CupScraper {
|
||||
public static void main(String[] args) {
|
||||
String caminhoChave = "service-account.json";
|
||||
String urlDatabase = "https://vdcscore-default-rtdb.firebaseio.com/";
|
||||
|
||||
try {
|
||||
System.out.println("--- A CONECTAR AO FIREBASE ---");
|
||||
if (FirebaseApp.getApps().isEmpty()) {
|
||||
FileInputStream serviceAccount = new FileInputStream(caminhoChave);
|
||||
FirebaseOptions options = FirebaseOptions.builder()
|
||||
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
|
||||
.setDatabaseUrl(urlDatabase)
|
||||
.build();
|
||||
FirebaseApp.initializeApp(options);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("ERRO FIREBASE!");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/cup/seasons/33/modality/1",
|
||||
"https://api.afavcd.pt/cup/seasons/33/modality/3"
|
||||
};
|
||||
String[] escaloes = { "seniores", "juniores" };
|
||||
|
||||
DatabaseReference refTaca = FirebaseDatabase.getInstance().getReference("taça");
|
||||
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
String url = urls[i];
|
||||
String escalao = escaloes[i];
|
||||
System.out.println("\n=== A PROCESSAR TAÇA PARA: " + escalao.toUpperCase() + " ===");
|
||||
|
||||
try {
|
||||
String json = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
Map<String, Object> root = gson.fromJson(json, new TypeToken<Map<String, Object>>() {}.getType());
|
||||
|
||||
if (!root.containsKey("games")) {
|
||||
System.out.println("Sem jogos para " + escalao);
|
||||
continue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, List<Map<String, Object>>> phases = (Map<String, List<Map<String, Object>>>) root.get("games");
|
||||
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : phases.entrySet()) {
|
||||
String phaseKeyRaw = entry.getKey();
|
||||
// Firebase friendly phase name
|
||||
String phaseKey = phaseKeyRaw.replaceAll("[\\.#\\$\\[\\]]", "_");
|
||||
|
||||
for (Map<String, Object> game : entry.getValue()) {
|
||||
try {
|
||||
Map<String, Object> matchMap = new HashMap<>();
|
||||
|
||||
matchMap.put("home_nome", game.get("homeName"));
|
||||
matchMap.put("away_nome", game.get("awayName"));
|
||||
matchMap.put("home_logo", game.get("homeLogo"));
|
||||
matchMap.put("away_logo", game.get("awayLogo"));
|
||||
matchMap.put("cupJorney", game.get("cupJorney"));
|
||||
|
||||
String hGoals = String.valueOf(game.get("homeGoals"));
|
||||
String aGoals = String.valueOf(game.get("awayGoals"));
|
||||
|
||||
boolean played = false;
|
||||
if (hGoals != null && !hGoals.equals("null") && !hGoals.trim().isEmpty()) {
|
||||
matchMap.put("home_golos", hGoals); // Some cup scores might be like "1p"
|
||||
played = true;
|
||||
}
|
||||
if (aGoals != null && !aGoals.equals("null") && !aGoals.trim().isEmpty()) {
|
||||
matchMap.put("away_golos", aGoals);
|
||||
played = true;
|
||||
}
|
||||
matchMap.put("played", played);
|
||||
|
||||
Object dateObj = game.get("date");
|
||||
if (dateObj != null && !String.valueOf(dateObj).equals("null")) {
|
||||
String dateStr = String.valueOf(dateObj);
|
||||
if (dateStr.contains("T")) {
|
||||
String[] parts = dateStr.split("T");
|
||||
matchMap.put("data", parts[0]);
|
||||
if (parts[1].length() >= 5) {
|
||||
matchMap.put("hora", parts[1].substring(0, 5));
|
||||
}
|
||||
} else {
|
||||
matchMap.put("data", dateStr);
|
||||
}
|
||||
}
|
||||
|
||||
Object fieldObj = game.get("field");
|
||||
if (fieldObj != null && !String.valueOf(fieldObj).equals("null")) {
|
||||
matchMap.put("campo", String.valueOf(fieldObj));
|
||||
}
|
||||
|
||||
Object reportUrlObj = game.get("reportURL");
|
||||
if (reportUrlObj != null && !String.valueOf(reportUrlObj).equals("null") && !String.valueOf(reportUrlObj).trim().isEmpty()) {
|
||||
matchMap.put("matchReportUrl", "https://api.afavcd.pt" + String.valueOf(reportUrlObj));
|
||||
}
|
||||
|
||||
String cupID = String.valueOf(game.get("cupID"));
|
||||
if (cupID.contains(".")) {
|
||||
cupID = cupID.substring(0, cupID.indexOf("."));
|
||||
}
|
||||
|
||||
refTaca.child(escalao).child(phaseKey).child(cupID).setValueAsync(matchMap);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Erro ao processar jogo: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("-> Dados de " + escalao + " agendados para envio.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erro a obter taça para " + escalao);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("\nAguardando confirmação do servidor (10s)...");
|
||||
Thread.sleep(10000);
|
||||
System.out.println("Processo de Taça concluído!");
|
||||
System.exit(0);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class DisciplineJorneyDiscovery {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/jorney/season/33/modality/1/discipline/1",
|
||||
"https://api.afavcd.pt/jorney/season/33/modality/3/discipline/1",
|
||||
"https://api.afavcd.pt/standings/season/33/modality/1/discipline/1",
|
||||
"https://api.afavcd.pt/standings/season/33/modality/3/discipline/1"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Result: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class DisciplineSearch {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/disciplines",
|
||||
"https://api.afavcd.pt/seasons/33/disciplines",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/disciplines"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Result: " + response.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class ExhaustiveApiSearch {
|
||||
public static void main(String[] args) {
|
||||
String base = "https://api.afavcd.pt/seasons/33";
|
||||
String[] paths = {
|
||||
"/modality/1/standings",
|
||||
"/modality/1/discipline/1/standings",
|
||||
"/modality/1/level/1/discipline/1/standings",
|
||||
"/teams/modality/1/standings",
|
||||
"/teams/modality/1/discipline/1/standings",
|
||||
"/teams/modality/1/jorney?jorney=1",
|
||||
"/teams/modality/1/jorney?number=1",
|
||||
"/teams/modality/1/jorney?id=1",
|
||||
"/teams/modality/1/jorney/all",
|
||||
"/teams/modality/1/games",
|
||||
"/teams/modality/1/all-games"
|
||||
};
|
||||
|
||||
for (String path : paths) {
|
||||
String url = base + path;
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 2) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class FinalApiDiscovery {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/jorney/modality/1/season/33",
|
||||
"https://api.afavcd.pt/jorney/active/modality/1/season/33",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/jorney",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/discipline/1/jorney"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 500)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class FindChampionships {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/campeonatos",
|
||||
"https://api.afavcd.pt/teams/modality/1/season/33/discipline/teams",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/discipline/1/jorney"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 500)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class FindLatestSeason {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 30; i < 40; i++) {
|
||||
String url = "https://api.afavcd.pt/seasons/" + i + "/teams/modality/1/discipline/teams";
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
String body = response.body();
|
||||
if (body.length() > 20) { // Some results found
|
||||
System.out.println("Season " + i + " exists. Length: " + body.length());
|
||||
} else {
|
||||
System.out.println("Season " + i + " returns empty array.");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Season " + i + " returned status: " + response.statusCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Season " + i + " failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class InspectJornadas {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/seasons/33/teams/modality/1/jorney",
|
||||
"https://api.afavcd.pt/seasons/33/teams/modality/3/jorney"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Inspecting: " + url);
|
||||
try {
|
||||
String body = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
System.out.println("Result length: " + body.length());
|
||||
System.out.println("Start of result: " + body.substring(0, Math.min(body.length(), 500)));
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class JorneyIdParamTest {
|
||||
public static void main(String[] args) {
|
||||
String base = "https://api.afavcd.pt/seasons/33/teams/modality/1/jorney";
|
||||
String[] urls = {
|
||||
base + "?jorneyID=2166",
|
||||
base + "?jorneyID=2165",
|
||||
base + "?jorneyID=2164",
|
||||
base + "?jorney=30",
|
||||
base + "?jorney=1"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class JorneyListDiscovery {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/jorneys/season/33/modality/1/discipline/1",
|
||||
"https://api.afavcd.pt/jorneys/active/modality/1/season/33",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/discipline/1/jorney",
|
||||
"https://api.afavcd.pt/jorney/active/modality/1/discipline/1/season/33"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Result: " + response.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,13 @@ public class Main {
|
||||
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());
|
||||
if (c.get("logoURL") != null) {
|
||||
String logoUrl = c.get("logoURL").toString();
|
||||
if (logoUrl != null && !logoUrl.startsWith("http") && !logoUrl.isEmpty()) {
|
||||
logoUrl = "https://api.afavcd.pt" + logoUrl;
|
||||
}
|
||||
club.setImageUrl(logoUrl);
|
||||
}
|
||||
if (c.get("president") != null)
|
||||
club.setPresident(c.get("president").toString());
|
||||
if (c.get("address") != null)
|
||||
@@ -92,9 +97,9 @@ public class Main {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Obter escalões (Apenas Seniores e Juniores conforme pedido)
|
||||
int[] idsEscaloes = { 1, 3 };
|
||||
String[] nomesEscaloes = { "seniores", "juniores" };
|
||||
// 2. Obter escalões
|
||||
int[] idsEscaloes = { 1, 3, 2 };
|
||||
String[] nomesEscaloes = { "seniores", "juniores", "feminino" };
|
||||
|
||||
for (int i = 0; i < idsEscaloes.length; i++) {
|
||||
int idAtual = idsEscaloes[i];
|
||||
@@ -166,12 +171,10 @@ public class Main {
|
||||
foto = (String) atleta.get("photoURl");
|
||||
}
|
||||
|
||||
if (foto != null && !foto.trim().isEmpty() && !foto.equalsIgnoreCase("null")) {
|
||||
if (!foto.startsWith("http")) {
|
||||
if (foto != null && !foto.startsWith("http")) {
|
||||
foto = "https://api.afavcd.pt" + foto;
|
||||
}
|
||||
p.setPhotoUrl(foto);
|
||||
}
|
||||
|
||||
if (atleta.get("birth") != null) {
|
||||
String date = (String) atleta.get("birth");
|
||||
@@ -192,7 +195,7 @@ public class Main {
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erro ao processar jogadores do clube ID: " + clubId);
|
||||
// e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
108
src/main/java/org/example/NewsScraper.java
Normal file
108
src/main/java/org/example/NewsScraper.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package org.example;
|
||||
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.FirebaseOptions;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.example.models.News;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NewsScraper {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String caminhoChave = "service-account.json";
|
||||
String urlDatabase = "https://vdcscore-default-rtdb.firebaseio.com/";
|
||||
|
||||
try {
|
||||
System.out.println("--- A CONECTAR AO FIREBASE ---");
|
||||
if (FirebaseApp.getApps().isEmpty()) {
|
||||
FileInputStream serviceAccount = new FileInputStream(caminhoChave);
|
||||
FirebaseOptions options = FirebaseOptions.builder()
|
||||
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
|
||||
.setDatabaseUrl(urlDatabase)
|
||||
.build();
|
||||
FirebaseApp.initializeApp(options);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("ERRO FIREBASE: Verifica o service-account.json!");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
System.out.println("\n--- A EXTRAIR NOTÍCIAS ---");
|
||||
|
||||
try {
|
||||
// Vamos extrair as primeiras páginas de notícias (ex: 1 a 3)
|
||||
// Para o resumo na app, talvez apenas a primeira página (mais recentes) baste.
|
||||
String urlNews = "https://api.afavcd.pt/news/1";
|
||||
|
||||
String jsonNews = Jsoup.connect(urlNews)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
Map<String, Object> responseMap = gson.fromJson(jsonNews, new TypeToken<Map<String, Object>>() {}.getType());
|
||||
List<Map<String, Object>> rows = (List<Map<String, Object>>) responseMap.get("rows");
|
||||
|
||||
List<News> newsList = new ArrayList<>();
|
||||
|
||||
if (rows != null) {
|
||||
for (Map<String, Object> row : rows) {
|
||||
News n = new News();
|
||||
if (row.get("newsID") != null) n.setNewsID((int) Double.parseDouble(row.get("newsID").toString()));
|
||||
if (row.get("title") != null) n.setTitle(row.get("title").toString());
|
||||
if (row.get("body") != null) n.setBody(row.get("body").toString());
|
||||
if (row.get("insertDate") != null) n.setInsertDate(row.get("insertDate").toString());
|
||||
|
||||
String photo = null;
|
||||
if (row.get("photoURl") != null) {
|
||||
photo = row.get("photoURl").toString();
|
||||
} else if (row.get("photoURL") != null) {
|
||||
photo = row.get("photoURL").toString();
|
||||
}
|
||||
|
||||
if (photo != null && !photo.isEmpty() && !photo.startsWith("http")) {
|
||||
photo = "https://api.afavcd.pt" + photo;
|
||||
}
|
||||
n.setPhotoURL(photo);
|
||||
|
||||
newsList.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Encontradas " + newsList.size() + " notícias.");
|
||||
|
||||
// Enviar para Firebase
|
||||
DatabaseReference refNoticias = FirebaseDatabase.getInstance().getReference("noticias");
|
||||
refNoticias.setValueAsync(newsList);
|
||||
System.out.println("-> Notícias enviadas para o Firebase.");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erro ao obter notícias.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("\nAguardando confirmação do servidor (5s)...");
|
||||
Thread.sleep(5000);
|
||||
System.out.println("Processo concluído!");
|
||||
System.exit(0);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class SeasonDetailTest {
|
||||
public static void main(String[] args) {
|
||||
String url = "https://api.afavcd.pt/seasons/33";
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class SeasonGamesTest {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/games/season/33/modality/1",
|
||||
"https://api.afavcd.pt/games/modality/1/season/33",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/games",
|
||||
"https://api.afavcd.pt/jorneys/season/33/modality/1"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.example.models.Club;
|
||||
import org.example.models.GameMatch;
|
||||
import org.example.models.TeamStanding;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
@@ -59,29 +58,19 @@ public class StandingsScraper {
|
||||
}.getType());
|
||||
|
||||
for (Map<String, Object> c : dadosClubes) {
|
||||
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());
|
||||
if (c.get("teamID") != null) {
|
||||
int clubId = (int) Double.parseDouble(c.get("teamID").toString());
|
||||
Club club = new Club();
|
||||
club.setId(clubId);
|
||||
|
||||
// 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());
|
||||
if (c.get("name") != null)
|
||||
club.setName(c.get("name").toString());
|
||||
if (c.get("logoURL") != null) {
|
||||
String logoUrl = c.get("logoURL").toString();
|
||||
if (logoUrl != null && !logoUrl.startsWith("http") && !logoUrl.isEmpty()) {
|
||||
logoUrl = "https://api.afavcd.pt" + logoUrl;
|
||||
}
|
||||
club.setImageUrl(logoUrl);
|
||||
}
|
||||
|
||||
clubesMap.put(clubId, club);
|
||||
}
|
||||
@@ -115,105 +104,44 @@ public class StandingsScraper {
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
Map<String, List<Map<String, Object>>> matchdaysMap = gson.fromJson(jsonJornadas,
|
||||
Map<String, List<Map<String, Object>>> matchdays = gson.fromJson(jsonJornadas,
|
||||
new TypeToken<Map<String, List<Map<String, Object>>>>() {
|
||||
}.getType());
|
||||
|
||||
Map<Integer, TeamStanding> standingsMap = new HashMap<>();
|
||||
Map<String, List<GameMatch>> jornadasParaFirebase = new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : matchdaysMap.entrySet()) {
|
||||
String nomeJornada = entry.getKey();
|
||||
List<Map<String, Object>> matchday = entry.getValue();
|
||||
List<GameMatch> matchesInJornada = new ArrayList<>();
|
||||
|
||||
for (List<Map<String, Object>> matchday : matchdays.values()) {
|
||||
for (Map<String, Object> match : matchday) {
|
||||
try {
|
||||
int homeTeamId = parseId(match.get("Home"));
|
||||
int awayTeamId = parseId(match.get("Away"));
|
||||
|
||||
// Ignorar jogos com equipas placeholder / de descanso para a classificação
|
||||
// Mas guardamos para as jornadas (podes decidir se queres filtrar ou não)
|
||||
// Ignorar jogos com equipas placeholder / de descanso
|
||||
if (homeTeamId < 0 || awayTeamId < 0)
|
||||
continue;
|
||||
|
||||
// Modelar o jogo para as Jornadas
|
||||
GameMatch game = new GameMatch();
|
||||
game.setHomeId(homeTeamId);
|
||||
game.setAwayId(awayTeamId);
|
||||
// Buscar dados dos clubes no mapa local para garantir nome e logo
|
||||
Club homeClub = clubesMap.get(homeTeamId);
|
||||
Club awayClub = clubesMap.get(awayTeamId);
|
||||
|
||||
game.setHomeName(homeClub != null ? homeClub.getName() : "Equipa " + homeTeamId);
|
||||
game.setAwayName(awayClub != null ? awayClub.getName() : "Equipa " + awayTeamId);
|
||||
game.setHomeLogo(homeClub != null ? homeClub.getImageUrl() : "");
|
||||
game.setAwayLogo(awayClub != null ? awayClub.getImageUrl() : "");
|
||||
|
||||
// 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
|
||||
if (parts[1].length() >= 5) {
|
||||
game.setGameHour(parts[1].substring(0, 5)); // HH:mm
|
||||
}
|
||||
} else {
|
||||
game.setGameDate(rawDate);
|
||||
game.setGameHour("");
|
||||
}
|
||||
|
||||
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() : "");
|
||||
|
||||
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;
|
||||
String homeGoalsStr = String.valueOf(match.get("homeGoals"));
|
||||
String awayGoalsStr = String.valueOf(match.get("awayGoals"));
|
||||
|
||||
if (homeGoalsStr != null && !homeGoalsStr.trim().isEmpty()
|
||||
&& !homeGoalsStr.equals("null")) {
|
||||
int homeGoals = (int) Double.parseDouble(homeGoalsStr);
|
||||
int awayGoals = (int) Double.parseDouble(awayGoalsStr);
|
||||
|
||||
game.setHomeGoals(homeGoals);
|
||||
game.setAwayGoals(awayGoals);
|
||||
|
||||
// Atualizar classificação
|
||||
// Inicializar as equipas caso não existam no standingsMap
|
||||
standingsMap.putIfAbsent(homeTeamId, createInitialStanding(homeTeamId, clubesMap));
|
||||
standingsMap.putIfAbsent(awayTeamId, createInitialStanding(awayTeamId, clubesMap));
|
||||
|
||||
standingsMap.get(homeTeamId).addMatchResult(homeGoals, awayGoals);
|
||||
standingsMap.get(awayTeamId).addMatchResult(awayGoals, homeGoals);
|
||||
} else {
|
||||
game.setHomeGoals(null);
|
||||
game.setAwayGoals(null);
|
||||
}
|
||||
|
||||
matchesInJornada.add(game);
|
||||
|
||||
} catch (Exception ex) {
|
||||
// Ignorar erro em um jogo específico (dados incorretos, etc)
|
||||
}
|
||||
}
|
||||
jornadasParaFirebase.put(nomeJornada, matchesInJornada);
|
||||
}
|
||||
|
||||
// Transformar em lista e ordenar a classificação
|
||||
// Transformar em lista e ordenar
|
||||
List<TeamStanding> sortedStandings = new ArrayList<>(standingsMap.values());
|
||||
Collections.sort(sortedStandings);
|
||||
|
||||
@@ -227,19 +155,94 @@ public class StandingsScraper {
|
||||
posicao++;
|
||||
}
|
||||
|
||||
// Enviar para Firebase - CLASSIFICAÇÕES
|
||||
// Enviar para Firebase (Classificações)
|
||||
DatabaseReference refClassificacoes = FirebaseDatabase.getInstance()
|
||||
.getReference("classificacoes").child(escalao);
|
||||
|
||||
refClassificacoes.setValueAsync(sortedStandings);
|
||||
System.out.println("-> Classificação de " + escalao + " enviada para o Firebase.");
|
||||
|
||||
// Enviar para Firebase - JORNADAS
|
||||
// Enviar para Firebase (Jornadas)
|
||||
DatabaseReference refJornadas = FirebaseDatabase.getInstance()
|
||||
.getReference("jornadas").child(escalao);
|
||||
|
||||
refJornadas.setValueAsync(jornadasParaFirebase);
|
||||
System.out.println("-> Jornadas de " + escalao + " enviadas para o Firebase (" + jornadasParaFirebase.size() + " jornadas).");
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : matchdays.entrySet()) {
|
||||
String jornadaNumber = entry.getKey();
|
||||
for (Map<String, Object> match : entry.getValue()) {
|
||||
try {
|
||||
int homeId = parseId(match.get("Home"));
|
||||
int awayId = parseId(match.get("Away"));
|
||||
|
||||
// Ignorar jogos com equipas placeholder / de descanso
|
||||
if (homeId < 0 || awayId < 0) continue;
|
||||
|
||||
Club homeClub = clubesMap.get(homeId);
|
||||
Club awayClub = clubesMap.get(awayId);
|
||||
|
||||
String homeName = homeClub != null ? homeClub.getName() : "Equipa " + homeId;
|
||||
String homeLogo = homeClub != null ? homeClub.getImageUrl() : "";
|
||||
String awayName = awayClub != null ? awayClub.getName() : "Equipa " + awayId;
|
||||
String awayLogo = awayClub != null ? awayClub.getImageUrl() : "";
|
||||
|
||||
Map<String, Object> matchMap = new HashMap<>();
|
||||
matchMap.put("home_nome", homeName);
|
||||
matchMap.put("away_nome", awayName);
|
||||
matchMap.put("home_logo", homeLogo);
|
||||
matchMap.put("away_logo", awayLogo);
|
||||
|
||||
String homeGoalsStr = String.valueOf(match.get("homeGoals"));
|
||||
String awayGoalsStr = String.valueOf(match.get("awayGoals"));
|
||||
|
||||
boolean played = false;
|
||||
if (homeGoalsStr != null && !homeGoalsStr.equals("null") && !homeGoalsStr.trim().isEmpty()) {
|
||||
matchMap.put("home_golos", (int) Double.parseDouble(homeGoalsStr));
|
||||
played = true;
|
||||
}
|
||||
|
||||
if (awayGoalsStr != null && !awayGoalsStr.equals("null") && !awayGoalsStr.trim().isEmpty()) {
|
||||
matchMap.put("away_golos", (int) Double.parseDouble(awayGoalsStr));
|
||||
played = true;
|
||||
}
|
||||
matchMap.put("played", played);
|
||||
|
||||
Object dateObj = match.get("date");
|
||||
if (dateObj != null && !String.valueOf(dateObj).equals("null")) {
|
||||
String dateStr = String.valueOf(dateObj);
|
||||
if (dateStr.contains("T")) {
|
||||
String[] parts = dateStr.split("T");
|
||||
matchMap.put("data", parts[0]);
|
||||
if (parts[1].length() >= 5) {
|
||||
matchMap.put("hora", parts[1].substring(0, 5));
|
||||
}
|
||||
} else {
|
||||
matchMap.put("data", dateStr);
|
||||
}
|
||||
}
|
||||
|
||||
Object fieldObj = match.get("field");
|
||||
if (fieldObj != null && !String.valueOf(fieldObj).equals("null") && !String.valueOf(fieldObj).trim().isEmpty()) {
|
||||
matchMap.put("campo", String.valueOf(fieldObj));
|
||||
}
|
||||
|
||||
Object reportUrlObj = match.get("reportURL");
|
||||
if (reportUrlObj != null && !String.valueOf(reportUrlObj).equals("null") && !String.valueOf(reportUrlObj).trim().isEmpty()) {
|
||||
matchMap.put("matchReportUrl", "https://api.afavcd.pt" + String.valueOf(reportUrlObj));
|
||||
}
|
||||
|
||||
String jorneyID = String.valueOf(match.get("jorneyID"));
|
||||
if (jorneyID != null && !jorneyID.equals("null")) {
|
||||
if (jorneyID.contains(".")) {
|
||||
jorneyID = jorneyID.substring(0, jorneyID.indexOf("."));
|
||||
}
|
||||
refJornadas.child(jornadaNumber).child(jorneyID).setValueAsync(matchMap);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Erro ao processar jogo na jornada " + jornadaNumber + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("-> Jornadas de " + escalao + " enviadas para o Firebase.");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erro a processar " + escalao);
|
||||
@@ -247,7 +250,6 @@ public class StandingsScraper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
System.out.println("\nAguardando confirmação do servidor (5s)...");
|
||||
Thread.sleep(5000);
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestApiSingular {
|
||||
public static void main(String[] args) {
|
||||
String url = "https://api.afavcd.pt/seasons/33/teams/modality/3/jorney";
|
||||
try {
|
||||
String body = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
System.out.println(body.substring(0, Math.min(body.length(), 2000)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestAthleteHeaders {
|
||||
public static void main(String[] args) {
|
||||
// Try club 1, modality 1, season 33
|
||||
String url = "https://api.afavcd.pt/teams/1/modality/1/season/33";
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body().substring(0, Math.min(response.body().length(), 500)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestAthleteJson {
|
||||
public static void main(String[] args) {
|
||||
// Club ID 1 (Arvore) and Modality 1 (Senior)
|
||||
String url = "https://api.afavcd.pt/teams/1/modality/1/season/33";
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body().substring(0, Math.min(response.body().length(), 2000)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestClubGames {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/teams/16/modality/1/season/33/games",
|
||||
"https://api.afavcd.pt/teams/16/modality/1/season/33/jorney",
|
||||
"https://api.afavcd.pt/games/modality/1/season/33"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestJornadaEndpoint {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/seasons/33/teams/modality/1/jorney/1",
|
||||
"https://api.afavcd.pt/seasons/33/teams/modality/1/jorney/2",
|
||||
"https://api.afavcd.pt/seasons/33/teams/modality/1/jornadas",
|
||||
"https://api.afavcd.pt/seasons/33/teams/modality/1/games"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestJorneyId {
|
||||
public static void main(String[] args) {
|
||||
// Try to fetch a specific journey by its ID
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/jorney/2166",
|
||||
"https://api.afavcd.pt/jorney/2165",
|
||||
"https://api.afavcd.pt/jorney/2164",
|
||||
"https://api.afavcd.pt/seasons/33/jorneys"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestJorneysPlural {
|
||||
public static void main(String[] args) {
|
||||
String url = "https://api.afavcd.pt/seasons/33/teams/modality/1/jorneys";
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body().substring(0, Math.min(response.body().length(), 1000)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestNewEndpoint {
|
||||
public static void main(String[] args) {
|
||||
String url = "https://api.afavcd.pt/seasons/33/teams/modality/1";
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Result: " + response.body().substring(0, Math.min(response.body().length(), 500)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.example;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
public class TestNewJornadaEndpoint {
|
||||
public static void main(String[] args) {
|
||||
String[] urls = {
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/jorney",
|
||||
"https://api.afavcd.pt/seasons/33/modality/3/jorney",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/discipline/1/jorney",
|
||||
"https://api.afavcd.pt/seasons/33/modality/1/level/1/discipline/1/jorney"
|
||||
};
|
||||
|
||||
for (String url : urls) {
|
||||
System.out.println("Testing: " + url);
|
||||
try {
|
||||
Connection.Response response = Jsoup.connect(url)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.method(Connection.Method.GET)
|
||||
.execute();
|
||||
System.out.println("Status: " + response.statusCode() + " Length: " + response.body().length());
|
||||
if (response.statusCode() == 200 && response.body().length() > 0) {
|
||||
System.out.println("Preview: " + response.body().substring(0, Math.min(response.body().length(), 200)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
178
src/main/java/org/example/TopScorersScraper.java
Normal file
178
src/main/java/org/example/TopScorersScraper.java
Normal file
@@ -0,0 +1,178 @@
|
||||
package org.example;
|
||||
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.FirebaseOptions;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.example.models.Club;
|
||||
import org.example.models.TopScorer;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.*;
|
||||
|
||||
public class TopScorersScraper {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String caminhoChave = "service-account.json";
|
||||
String urlDatabase = "https://vdcscore-default-rtdb.firebaseio.com/";
|
||||
|
||||
try {
|
||||
System.out.println("--- A CONECTAR AO FIREBASE ---");
|
||||
if (FirebaseApp.getApps().isEmpty()) {
|
||||
FileInputStream serviceAccount = new FileInputStream(caminhoChave);
|
||||
FirebaseOptions options = FirebaseOptions.builder()
|
||||
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
|
||||
.setDatabaseUrl(urlDatabase)
|
||||
.build();
|
||||
FirebaseApp.initializeApp(options);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("ERRO FIREBASE: Verifica o service-account.json!");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
Map<Integer, Club> clubesMap = new HashMap<>();
|
||||
|
||||
// 1. Obter todos os Clubes para ter logos e nomes reais
|
||||
System.out.println("\n--- A EXTRAIR DADOS DOS CLUBES ---");
|
||||
try {
|
||||
String urlTodosClubes = "https://api.afavcd.pt/teams";
|
||||
String jsonTodosClubes = Jsoup.connect(urlTodosClubes)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.maxBodySize(0)
|
||||
.timeout(30000)
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
List<Map<String, Object>> dadosClubes = gson.fromJson(jsonTodosClubes,
|
||||
new TypeToken<List<Map<String, Object>>>() {}.getType());
|
||||
|
||||
for (Map<String, Object> c : dadosClubes) {
|
||||
if (c.get("teamID") != null) {
|
||||
int clubId = (int) Double.parseDouble(c.get("teamID").toString());
|
||||
Club club = new Club();
|
||||
club.setId(clubId);
|
||||
if (c.get("name") != null) club.setName(c.get("name").toString());
|
||||
if (c.get("logoURL") != null) {
|
||||
String logoUrl = c.get("logoURL").toString();
|
||||
if (logoUrl != null && !logoUrl.startsWith("http") && !logoUrl.isEmpty()) {
|
||||
logoUrl = "https://api.afavcd.pt" + logoUrl;
|
||||
}
|
||||
club.setImageUrl(logoUrl);
|
||||
}
|
||||
clubesMap.put(clubId, club);
|
||||
}
|
||||
}
|
||||
System.out.println("Encontrados " + clubesMap.size() + " clubes.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erro ao obter lista de clubes.");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
int[] modalidades = { 1, 3 }; // 1: Seniores, 3: Juniores
|
||||
String[] nomesEscaloes = { "seniores", "juniores" };
|
||||
|
||||
for (int i = 0; i < modalidades.length; i++) {
|
||||
int modalidade = modalidades[i];
|
||||
String escalao = nomesEscaloes[i];
|
||||
|
||||
System.out.println("\n--- A EXTRAIR MARCADORES PARA: " + escalao.toUpperCase() + " ---");
|
||||
|
||||
String urlDiscipline = "https://api.afavcd.pt/teams/modality/" + modalidade + "/season/33/discipline";
|
||||
try {
|
||||
String jsonDiscipline = Jsoup.connect(urlDiscipline)
|
||||
.ignoreContentType(true)
|
||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.header("Referer", "https://www.afavcd.pt/")
|
||||
.header("Origin", "https://www.afavcd.pt")
|
||||
.maxBodySize(0)
|
||||
.timeout(60000)
|
||||
.method(Connection.Method.GET)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
Map<String, Object> root = gson.fromJson(jsonDiscipline, new TypeToken<Map<String, Object>>() {}.getType());
|
||||
Map<String, List<Map<String, Object>>> teams = (Map<String, List<Map<String, Object>>>) root.get("teams");
|
||||
|
||||
List<TopScorer> scorersList = new ArrayList<>();
|
||||
|
||||
if (teams != null) {
|
||||
for (List<Map<String, Object>> players : teams.values()) {
|
||||
for (Map<String, Object> player : players) {
|
||||
String playerName = (String) player.get("fullName");
|
||||
String playerPhoto = (String) player.get("photoURl");
|
||||
int clubId = (int) Double.parseDouble(player.get("teamID").toString());
|
||||
|
||||
Club club = clubesMap.get(clubId);
|
||||
String clubName = club != null ? club.getName() : (String) player.get("name");
|
||||
String clubLogo = club != null ? club.getImageUrl() : "";
|
||||
|
||||
List<Map<String, Object>> jorneys = (List<Map<String, Object>>) player.get("jorneys");
|
||||
int totalGoals = 0;
|
||||
if (jorneys != null) {
|
||||
for (Map<String, Object> j : jorneys) {
|
||||
Object goalsObj = j.get("totalGoals");
|
||||
if (goalsObj != null && !goalsObj.toString().isEmpty()) {
|
||||
try {
|
||||
totalGoals += (int) Double.parseDouble(goalsObj.toString());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalGoals > 0) {
|
||||
TopScorer ts = new TopScorer();
|
||||
ts.setPlayerName(playerName);
|
||||
ts.setPlayerPhoto(playerPhoto != null && !playerPhoto.startsWith("http") ? "https://api.afavcd.pt" + playerPhoto : playerPhoto);
|
||||
ts.setClubName(clubName);
|
||||
ts.setClubLogo(clubLogo);
|
||||
ts.setGoals(totalGoals);
|
||||
scorersList.add(ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ordenar por golos
|
||||
Collections.sort(scorersList);
|
||||
|
||||
// Definir posições e limitar aos top 20 (opcional, mas comum)
|
||||
for (int j = 0; j < scorersList.size(); j++) {
|
||||
scorersList.get(j).setPosition(j + 1);
|
||||
}
|
||||
|
||||
// Enviar para Firebase
|
||||
DatabaseReference refMarcadores = FirebaseDatabase.getInstance()
|
||||
.getReference("marcadores").child(escalao);
|
||||
|
||||
refMarcadores.setValueAsync(scorersList);
|
||||
System.out.println("-> " + scorersList.size() + " marcadores de " + escalao + " enviados para o Firebase.");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erro ao processar marcadores de " + escalao);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("\nAguardando confirmação do servidor (5s)...");
|
||||
Thread.sleep(5000);
|
||||
System.out.println("Processo concluído!");
|
||||
System.exit(0);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
package org.example.models;
|
||||
|
||||
import com.google.firebase.database.PropertyName;
|
||||
|
||||
public class GameMatch {
|
||||
|
||||
@PropertyName("home_id")
|
||||
private int homeId;
|
||||
|
||||
@PropertyName("away_id")
|
||||
private int awayId;
|
||||
|
||||
@PropertyName("home_nome")
|
||||
private String homeName;
|
||||
|
||||
@PropertyName("away_nome")
|
||||
private String awayName;
|
||||
|
||||
@PropertyName("home_logo")
|
||||
private String homeLogo;
|
||||
|
||||
@PropertyName("away_logo")
|
||||
private String awayLogo;
|
||||
|
||||
@PropertyName("home_golos")
|
||||
private Integer homeGoals;
|
||||
|
||||
@PropertyName("away_golos")
|
||||
private Integer awayGoals;
|
||||
|
||||
@PropertyName("data")
|
||||
private String gameDate;
|
||||
|
||||
@PropertyName("hora")
|
||||
private String gameHour;
|
||||
|
||||
@PropertyName("campo")
|
||||
private String stadium;
|
||||
|
||||
@PropertyName("report_url")
|
||||
private String reportUrl;
|
||||
|
||||
public GameMatch() {
|
||||
}
|
||||
|
||||
@PropertyName("home_id")
|
||||
public int getHomeId() {
|
||||
return homeId;
|
||||
}
|
||||
|
||||
@PropertyName("home_id")
|
||||
public void setHomeId(int homeId) {
|
||||
this.homeId = homeId;
|
||||
}
|
||||
|
||||
@PropertyName("away_id")
|
||||
public int getAwayId() {
|
||||
return awayId;
|
||||
}
|
||||
|
||||
@PropertyName("away_id")
|
||||
public void setAwayId(int awayId) {
|
||||
this.awayId = awayId;
|
||||
}
|
||||
|
||||
@PropertyName("home_nome")
|
||||
public String getHomeName() {
|
||||
return homeName;
|
||||
}
|
||||
|
||||
@PropertyName("home_nome")
|
||||
public void setHomeName(String homeName) {
|
||||
this.homeName = homeName;
|
||||
}
|
||||
|
||||
@PropertyName("away_nome")
|
||||
public String getAwayName() {
|
||||
return awayName;
|
||||
}
|
||||
|
||||
@PropertyName("away_nome")
|
||||
public void setAwayName(String awayName) {
|
||||
this.awayName = awayName;
|
||||
}
|
||||
|
||||
@PropertyName("home_logo")
|
||||
public String getHomeLogo() {
|
||||
return homeLogo;
|
||||
}
|
||||
|
||||
@PropertyName("home_logo")
|
||||
public void setHomeLogo(String homeLogo) {
|
||||
this.homeLogo = homeLogo;
|
||||
}
|
||||
|
||||
@PropertyName("away_logo")
|
||||
public String getAwayLogo() {
|
||||
return awayLogo;
|
||||
}
|
||||
|
||||
@PropertyName("away_logo")
|
||||
public void setAwayLogo(String awayLogo) {
|
||||
this.awayLogo = awayLogo;
|
||||
}
|
||||
|
||||
@PropertyName("home_golos")
|
||||
public Integer getHomeGoals() {
|
||||
return homeGoals;
|
||||
}
|
||||
|
||||
@PropertyName("home_golos")
|
||||
public void setHomeGoals(Integer homeGoals) {
|
||||
this.homeGoals = homeGoals;
|
||||
}
|
||||
|
||||
@PropertyName("away_golos")
|
||||
public Integer getAwayGoals() {
|
||||
return awayGoals;
|
||||
}
|
||||
|
||||
@PropertyName("away_golos")
|
||||
public void setAwayGoals(Integer awayGoals) {
|
||||
this.awayGoals = awayGoals;
|
||||
}
|
||||
|
||||
@PropertyName("data")
|
||||
public String getGameDate() {
|
||||
return gameDate;
|
||||
}
|
||||
|
||||
@PropertyName("data")
|
||||
public void setGameDate(String gameDate) {
|
||||
this.gameDate = gameDate;
|
||||
}
|
||||
|
||||
@PropertyName("hora")
|
||||
public String getGameHour() {
|
||||
return gameHour;
|
||||
}
|
||||
|
||||
@PropertyName("hora")
|
||||
public void setGameHour(String gameHour) {
|
||||
this.gameHour = gameHour;
|
||||
}
|
||||
|
||||
@PropertyName("campo")
|
||||
public String getStadium() {
|
||||
return stadium;
|
||||
}
|
||||
|
||||
@PropertyName("campo")
|
||||
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;
|
||||
}
|
||||
}
|
||||
52
src/main/java/org/example/models/News.java
Normal file
52
src/main/java/org/example/models/News.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.example.models;
|
||||
|
||||
public class News {
|
||||
private int newsID;
|
||||
private String title;
|
||||
private String body;
|
||||
private String insertDate;
|
||||
private String photoURL;
|
||||
|
||||
public News() {
|
||||
}
|
||||
|
||||
public int getNewsID() {
|
||||
return newsID;
|
||||
}
|
||||
|
||||
public void setNewsID(int newsID) {
|
||||
this.newsID = newsID;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getInsertDate() {
|
||||
return insertDate;
|
||||
}
|
||||
|
||||
public void setInsertDate(String insertDate) {
|
||||
this.insertDate = insertDate;
|
||||
}
|
||||
|
||||
public String getPhotoURL() {
|
||||
return photoURL;
|
||||
}
|
||||
|
||||
public void setPhotoURL(String photoURL) {
|
||||
this.photoURL = photoURL;
|
||||
}
|
||||
}
|
||||
70
src/main/java/org/example/models/TopScorer.java
Normal file
70
src/main/java/org/example/models/TopScorer.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package org.example.models;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TopScorer implements Serializable, Comparable<TopScorer> {
|
||||
|
||||
private String playerName;
|
||||
private String playerPhoto;
|
||||
private String clubName;
|
||||
private String clubLogo;
|
||||
private int goals;
|
||||
private int position;
|
||||
|
||||
public TopScorer() {
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
public String getPlayerPhoto() {
|
||||
return playerPhoto;
|
||||
}
|
||||
|
||||
public void setPlayerPhoto(String playerPhoto) {
|
||||
this.playerPhoto = playerPhoto;
|
||||
}
|
||||
|
||||
public String getClubName() {
|
||||
return clubName;
|
||||
}
|
||||
|
||||
public void setClubName(String clubName) {
|
||||
this.clubName = clubName;
|
||||
}
|
||||
|
||||
public String getClubLogo() {
|
||||
return clubLogo;
|
||||
}
|
||||
|
||||
public void setClubLogo(String clubLogo) {
|
||||
this.clubLogo = clubLogo;
|
||||
}
|
||||
|
||||
public int getGoals() {
|
||||
return goals;
|
||||
}
|
||||
|
||||
public void setGoals(int goals) {
|
||||
this.goals = goals;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TopScorer other) {
|
||||
// Ordenar por golos decrescente
|
||||
return Integer.compare(other.getGoals(), this.getGoals());
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user