diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fac4d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ +.kotlin + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2a65317 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5058a74 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..ee5dc69 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("java") +} + +group = "org.example" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.10.0")) + testImplementation("org.junit.jupiter:junit-jupiter") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") + implementation("org.jsoup:jsoup:1.17.2") + implementation("com.google.firebase:firebase-admin:9.2.0") + implementation("com.google.code.gson:gson:2.10.1") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f7ce596 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Feb 03 10:22:36 WET 2026 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..ac1b06f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/service-account.json b/service-account.json new file mode 100644 index 0000000..85f0884 --- /dev/null +++ b/service-account.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "vdcscore", + "private_key_id": "864360006a4a8d9c2bfb8be0d0382de235cca590", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCsediXpryWvOI8\nrb/l6QQ8EWAtvqeDCmHXuliPQg4aXF1q70rIi8eRLEVvig/WQeWv/hs/A0Bc3X6F\nMr3W3ht0VKlHL8JKuqli23eYmppaxpG0QFTk1UsJje1q+iuMI6tjOql+Zy5DIWW0\nLLCWTCRWMt5Cwf5qWFwHWsmGJwLqKHkglScNwWWpRH/t2dWXWxdVz/DjsyS7gw90\nb+GmNPpq8DhoFe2eTSL2G/dDrOhsKNKIlqv2pMdeKXKWOoS9ZHjjVMVquoh5nboh\n+LzjEMpVgD3fNAq8vb4e2FsevhnLe71OJVEb3puvybbgOKiQBUmFhBebBti5a+kA\n/HSjTXGdAgMBAAECggEAAbK0fvijUgxrkCfTxCeRR/gddhF4mNHoTVVgkEjeyvKl\nwnDOZy3gCG+LpXYpSO+wJv5JUzQVlRdizaJ1HnjBbCsZCBlvC8NkyxNp+4SwU+UZ\n8jmXAjJK2JsZPz+bjslVeq4erEHezSOTzxO3MkRX6lTLyXwypHHYtnfS8dQKCs6S\nmS44rG7zO1QPKm9JZL2t0q/2w+yQDrGuKEG/jn8xLK/YGbYcD7Mz8sGayK4GUlJc\nBfQGsuFHIEGQUstxANdvdwDKWabDFZSOQ5P1sMB9ljLd+FMwwdd15zn4tmG9mmIN\nazUSTIRmXnh0Dz9CAudUh+9wxAE8nsdherE3P2O4kQKBgQDirCroc17Fj9TDoO87\n5Y4ttBSjGsJK8A+ZGGx6lGZ1sT4hBY1m3Ljfeaq5Tcan1zASD21DyKE8nizu2dar\nftbyODpLK4b7YY/l7q72rW8BbJo4+0u7zNuEFZ5wyhkKV3qfad3WbOWEaRrgk27Q\nm8bD4A9+fGEYtWrhARodouKL6QKBgQDCypVVMWlOBaCX6MDmi/QKSowSek5wcYI8\nzNayaSOufLtIfSi6HzMf/gkTpZ0RUf3mKuiMcsVNb+jzn8W63sJ/g9llIizkn7ns\nBmbUX2+x4HDMx+PpUV0ydaCXkwbZexo1k4Gn+BQGiZJCLNBE/7R1KmYy8JYZv8wN\nN/dbG5cLlQKBgQCGZQAXzHeveUT0LJJLmCKBdJkbz7zNA6Kr6fA/iYdqVol4uLsK\n9uliDtgrgDK9xveIbb8iBm2a7EnF4EDIc67r9GyTrx4cI89Wy/rO5SvA02xpRo2z\nrpWkrdDAHQNVv2JD7FgMT4qRxGOcLa3xX7ss3ccx/nrvVHknKSkb0zyxKQKBgQCL\nc4ixMuyWpMSxvDnNU0hkzbW1zMW3DiwU5viVRVv8IOPbI28yv/9T2gQZgqkNq0s/\nqlxNoCTMKV/2ed2OyMcpjvTlyC+nhQoPhQ284I4QJAPdNwVdFZjI9RkBKoruy4iZ\n7n4WCC4d+AMzSO3ZV86TSsVblo1+5aZpmDWHjhr2eQKBgEH0/mw532/9gX0SPrFh\nWlYyYs+GGgCkJZem+dtwKqtEII3fm3VE4RKfxKZ0WPwSHwtRkf5dxmliWS+u2ZZA\nB3CEOfnwqqPgcmADioWE3psv2V18yf3iN1jrkxl1f9rvz51YsYvqem6bJ03MhLym\n8eFeMDwnVx98E3N6k6Q3BY+O\n-----END PRIVATE KEY-----\n", + "client_email": "firebase-adminsdk-fbsvc@vdcscore.iam.gserviceaccount.com", + "client_id": "108098848950522004963", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40vdcscore.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" +} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..d55be2a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "testeScraper" \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java new file mode 100644 index 0000000..e6c60a7 --- /dev/null +++ b/src/main/java/org/example/Main.java @@ -0,0 +1,142 @@ +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.Player; +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 Main { + 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; + } + + int[] idsEscaloes = {1, 3, 2}; + String[] nomesEscaloes = {"seniores", "juniores", "feminino"}; + Gson gson = new Gson(); + + for (int i = 0; i < idsEscaloes.length; i++) { + int idAtual = idsEscaloes[i]; + String nomeAtual = nomesEscaloes[i]; + + System.out.println("\n========================================"); + System.out.println("A EXTRAIR DADOS PARA: " + nomeAtual.toUpperCase()); + System.out.println("========================================"); + + String urlClubes = "https://api.afavcd.pt/teams/modality/" + idAtual + "/season/33/discipline/teams"; + + try { + String jsonResponse = Jsoup.connect(urlClubes) + .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(); + + List> dadosClubes = gson.fromJson(jsonResponse, new TypeToken>>() {}.getType()); + + for (Map dadoClube : dadosClubes) { + int clubId = -1; + + // CORREÇÃO AQUI: Tratar o número como Double primeiro para evitar NumberFormatException + if (dadoClube.get("teamID") != null) { + clubId = (int) Double.parseDouble(dadoClube.get("teamID").toString()); + } + + if (clubId == -1) continue; // Salta se o ID for inválido + + String urlJogadores = "https://api.afavcd.pt/teams/" + clubId + "/modality/" + idAtual + "/season/33"; + + try { + String jsonJogadores = Jsoup.connect(urlJogadores) + .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(); + + List> dadosJogadores = gson.fromJson(jsonJogadores, new TypeToken>>() {}.getType()); + ArrayList listaJogadoresDoClube = new ArrayList<>(); + + for (Map atleta : dadosJogadores) { + if (atleta.get("fullName") != null) { + Player p = new Player(); + p.setName((String) atleta.get("fullName")); + + String foto = (String) atleta.get("photoURL"); + if (foto != null && !foto.startsWith("http")) { + foto = "https://api.afavcd.pt" + foto; + } + p.setPhotoUrl(foto); + + if (atleta.get("birth") != null) p.setBirthDate((String) atleta.get("birth")); + if (atleta.get("naturalness") != null) p.setNaturalness((String) atleta.get("naturalness")); + + listaJogadoresDoClube.add(p); + } + } + + DatabaseReference ref = FirebaseDatabase.getInstance() + .getReference("clubes") + .child(String.valueOf(clubId - 1)) // Mantive o teu -1, assume-se que é a tua lógica de IDs + .child("listaDeJogadores"); + + // CORREÇÃO AQUI: Gravar a listaJogadoresDoClube e não a listaParaFirebase que estava vazia + ref.setValueAsync(listaJogadoresDoClube); + + System.out.println("SUCESSO: Jogadores do Clube ID " + clubId + " (" + nomeAtual.toUpperCase() + ") enviados para o Firebase!"); + + } catch (Exception e) { + System.err.println("Erro ao processar jogadores do clube ID: " + clubId); + e.printStackTrace(); + } + } + + } catch (Exception e) { + System.err.println("Erro a processar o escalão " + nomeAtual + ": HTTP error fetching URL."); + e.printStackTrace(); + } + } + + try { + System.out.println("\nAguardando confirmação do servidor (10s)..."); + Thread.sleep(10000); + System.out.println("Processo concluído! Podes verificar o teu Firebase."); + System.exit(0); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/example/PlayersScraper.java b/src/main/java/org/example/PlayersScraper.java new file mode 100644 index 0000000..e5b01c2 --- /dev/null +++ b/src/main/java/org/example/PlayersScraper.java @@ -0,0 +1,7 @@ +package org.example; + +public class PlayersScraper { + public static void main(String[] args) { + + } +} diff --git a/src/main/java/org/example/models/Club.java b/src/main/java/org/example/models/Club.java new file mode 100644 index 0000000..4f8554f --- /dev/null +++ b/src/main/java/org/example/models/Club.java @@ -0,0 +1,134 @@ +package org.example.models; + +import com.google.firebase.database.PropertyName; +import java.util.ArrayList; +import java.util.List; + +public class Club { + @PropertyName("id") + private int id; + + @PropertyName("nome") + private String name; + + @PropertyName("imagem") + private String imageUrl; + + @PropertyName("campo") + private String stadium; + + @PropertyName("ano fundacao") + private int foundationYear; + + @PropertyName("morada") + private String address; + + @PropertyName("presidente") + private String president; + + @PropertyName("jogadores") + private ArrayList players; + + public Club() { + // Default constructor for Firebase + players = new ArrayList<>(); + } + + public Club(int id, String name, String imageUrl, String stadium, int foundationYear, String address, + String president) { + this.id = id; + this.name = name; + this.imageUrl = imageUrl; + this.stadium = stadium; + this.foundationYear = foundationYear; + this.address = address; + this.president = president; + this.players = new ArrayList<>(); + } + + @PropertyName("id") + public int getId() { + return id; + } + + @PropertyName("id") + public void setId(int id) { + this.id = id; + } + + @PropertyName("nome") + public String getName() { + return name; + } + + @PropertyName("nome") + public void setName(String name) { + this.name = name; + } + + @PropertyName("imagem") + public String getImageUrl() { + return imageUrl; + } + + @PropertyName("imagem") + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + @PropertyName("campo") + public String getStadium() { + return stadium; + } + + @PropertyName("campo") + public void setStadium(String stadium) { + this.stadium = stadium; + } + + @PropertyName("ano fundacao") + public int getFoundationYear() { + return foundationYear; + } + + @PropertyName("ano fundacao") + public void setFoundationYear(int foundationYear) { + this.foundationYear = foundationYear; + } + + @PropertyName("morada") + public String getAddress() { + return address; + } + + @PropertyName("morada") + public void setAddress(String address) { + this.address = address; + } + + @PropertyName("presidente") + public String getPresident() { + return president; + } + + @PropertyName("presidente") + public void setPresident(String president) { + this.president = president; + } + + @PropertyName("jogadores") + public ArrayList getPlayersMap() { + return players; + } + + @PropertyName("jogadores") + public void setPlayersMap(ArrayList players) { + this.players = players; + } + + public List getPlayersList() { + if (players == null) + return new ArrayList<>(); + return new ArrayList<>(players); + } +} diff --git a/src/main/java/org/example/models/Game.java b/src/main/java/org/example/models/Game.java new file mode 100644 index 0000000..bba9848 --- /dev/null +++ b/src/main/java/org/example/models/Game.java @@ -0,0 +1,102 @@ +package org.example.models; + +public class Game { + private String id; + private String homeTeamId; + private String awayTeamId; + private String homeTeamName; + private String awayTeamName; + private int homeScore; + private int awayScore; + private boolean isFinished; + private long timestamp; + + public Game() { + // Required for Firebase + } + + public Game(String id, String homeTeamId, String awayTeamId, String homeTeamName, String awayTeamName, + long timestamp) { + this.id = id; + this.homeTeamId = homeTeamId; + this.awayTeamId = awayTeamId; + this.homeTeamName = homeTeamName; + this.awayTeamName = awayTeamName; + this.timestamp = timestamp; + this.isFinished = false; + this.homeScore = 0; + this.awayScore = 0; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getHomeTeamId() { + return homeTeamId; + } + + public void setHomeTeamId(String homeTeamId) { + this.homeTeamId = homeTeamId; + } + + public String getAwayTeamId() { + return awayTeamId; + } + + public void setAwayTeamId(String awayTeamId) { + this.awayTeamId = awayTeamId; + } + + public String getHomeTeamName() { + return homeTeamName; + } + + public void setHomeTeamName(String homeTeamName) { + this.homeTeamName = homeTeamName; + } + + public String getAwayTeamName() { + return awayTeamName; + } + + public void setAwayTeamName(String awayTeamName) { + this.awayTeamName = awayTeamName; + } + + public int getHomeScore() { + return homeScore; + } + + public void setHomeScore(int homeScore) { + this.homeScore = homeScore; + } + + public int getAwayScore() { + return awayScore; + } + + public void setAwayScore(int awayScore) { + this.awayScore = awayScore; + } + + public boolean isFinished() { + return isFinished; + } + + public void setFinished(boolean finished) { + isFinished = finished; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +} diff --git a/src/main/java/org/example/models/Jornada.java b/src/main/java/org/example/models/Jornada.java new file mode 100644 index 0000000..6e46c6f --- /dev/null +++ b/src/main/java/org/example/models/Jornada.java @@ -0,0 +1,55 @@ +package org.example.models; + +import java.util.ArrayList; +import java.util.List; + +public class Jornada { + private String id; + private int number; + private List games; + private boolean isCurrent; + + public Jornada() { + // Required for Firebase + this.games = new ArrayList<>(); + } + + public Jornada(String id, int number) { + this.id = id; + this.number = number; + this.games = new ArrayList<>(); + this.isCurrent = false; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public List getGames() { + return games; + } + + public void setGames(List games) { + this.games = games; + } + + public boolean isCurrent() { + return isCurrent; + } + + public void setCurrent(boolean current) { + isCurrent = current; + } +} diff --git a/src/main/java/org/example/models/Player.java b/src/main/java/org/example/models/Player.java new file mode 100644 index 0000000..e79afee --- /dev/null +++ b/src/main/java/org/example/models/Player.java @@ -0,0 +1,83 @@ +package org.example.models; + +import com.google.firebase.database.PropertyName; + +public class Player { + + // Na API da AFAVCD o ID do jogador chama-se "playerID", + // mas na nossa BD vamos chamar-lhe "id" + @PropertyName("id") + private int id; + + // O nome que a API manda é "fullName" + @PropertyName("nome") + private String name; + + // A foto que a API manda é "photoURL" + @PropertyName("foto") + private String photoUrl; + + // A data de nascimento que a API manda é "birth" + @PropertyName("data_nascimento") + private String birthDate; + + // (Opcional) A naturalidade que a API manda é "naturalness" + @PropertyName("naturalidade") + private String naturalness; + + // Construtor vazio (obrigatório para o Firebase funcionar!) + public Player() { + } + + // --- GETTERS E SETTERS --- + + @PropertyName("id") + public int getId() { + return id; + } + + @PropertyName("id") + public void setId(int id) { + this.id = id; + } + + @PropertyName("nome") + public String getName() { + return name; + } + + @PropertyName("nome") + public void setName(String name) { + this.name = name; + } + + @PropertyName("foto") + public String getPhotoUrl() { + return photoUrl; + } + + @PropertyName("foto") + public void setPhotoUrl(String photoUrl) { + this.photoUrl = photoUrl; + } + + @PropertyName("data_nascimento") + public String getBirthDate() { + return birthDate; + } + + @PropertyName("data_nascimento") + public void setBirthDate(String birthDate) { + this.birthDate = birthDate; + } + + @PropertyName("naturalidade") + public String getNaturalness() { + return naturalness; + } + + @PropertyName("naturalidade") + public void setNaturalness(String naturalness) { + this.naturalness = naturalness; + } +} \ No newline at end of file