136 lines
5.5 KiB
Java
136 lines
5.5 KiB
Java
package de.jeyp91;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import de.jeyp91.apifootball.APIFootballUpdater;
|
|
import de.jeyp91.tippliga.TLWMatchdaysUpdater;
|
|
import de.jeyp91.tippliga.TLWMatchesCreatorFootball;
|
|
import de.jeyp91.tippliga.TLWMatchesResultsUpdater;
|
|
import de.jeyp91.tippliga.TLWMatchesUpdaterFootball;
|
|
import de.jeyp91.tippliga.TLWTeamsUpdater;
|
|
import de.jeyp91.tippligaforum.MatchesListForumUpdater;
|
|
import de.jeyp91.tippligaforum.SeasonForumPostsCreator;
|
|
import de.jeyp91.tippligaforum.TippligaConfigProvider;
|
|
import de.jeyp91.tippligaforum.TippligaSQLConnector;
|
|
import de.jeyp91.whatsapp.WhatsAppNotifier;
|
|
import net.sourceforge.argparse4j.ArgumentParsers;
|
|
import net.sourceforge.argparse4j.inf.ArgumentParser;
|
|
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
|
import net.sourceforge.argparse4j.inf.Namespace;
|
|
|
|
/**
|
|
* Hello world!
|
|
*
|
|
*/
|
|
public class App {
|
|
|
|
private static String mode;
|
|
private static int season;
|
|
private static int league;
|
|
private static String configFile;
|
|
private static final Logger logger = LoggerFactory.getLogger(App.class);
|
|
|
|
public static void main(String[] args) {
|
|
// SLF4J does not require explicit configuration here
|
|
// Configuration can be done via an external configuration file (e.g., logback.xml)
|
|
initOptions(args);
|
|
String sql = "";
|
|
String beautifulInfo = "";
|
|
switch (mode) {
|
|
case "MatchdaysUpdater" -> {
|
|
TLWMatchdaysUpdater matchdaysUpdater = new TLWMatchdaysUpdater(season, league, configFile);
|
|
sql = matchdaysUpdater.getUpdateSql();
|
|
beautifulInfo = matchdaysUpdater.getBeautifulInfo();
|
|
matchdaysUpdater.updateGoogleCalendar();
|
|
}
|
|
case "MatchesCreatorFootball" -> {
|
|
TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(season, league, configFile);
|
|
sql = creator.getSQLInsertString();
|
|
}
|
|
case "MatchesUpdaterFootball" -> {
|
|
TLWMatchesUpdaterFootball tlwMatchesUpdaterFootball = new TLWMatchesUpdaterFootball(season, league, configFile);
|
|
sql = tlwMatchesUpdaterFootball.getUpdateSQL();
|
|
beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo();
|
|
}
|
|
case "MatchesResultsUpdater" -> {
|
|
TLWMatchesResultsUpdater tlwMatchesResultsUpdater = new TLWMatchesResultsUpdater(season, league, configFile);
|
|
beautifulInfo = tlwMatchesResultsUpdater.getBeautifulInfo();
|
|
}
|
|
case "TeamsUpdater" -> {
|
|
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
|
|
sql = teamsUpdater.getInsertSQL();
|
|
}
|
|
case "APIFootballUpdater" -> {
|
|
APIFootballUpdater apiFootballUpdater = new APIFootballUpdater();
|
|
apiFootballUpdater.updateAllFixtures(season);
|
|
apiFootballUpdater.updateAllRounds(season);
|
|
}
|
|
case "MatchesListGistUpdater" -> {
|
|
MatchesListForumUpdater matchesListForumUpdater = new MatchesListForumUpdater();
|
|
matchesListForumUpdater.updateAllLeagues(season);
|
|
}
|
|
case "SeasonPreparation" -> {
|
|
SeasonForumPostsCreator creator = new SeasonForumPostsCreator(season);
|
|
creator.createAllPosts();
|
|
}
|
|
case "PostChecksum" -> {
|
|
TippligaConfigProvider configProvider = new TippligaConfigProvider(season);
|
|
String checksum = configProvider.getChecksumOfConfigPost(configFile);
|
|
System.out.println(checksum);
|
|
}
|
|
case "WhatsAppNotifier" -> {
|
|
WhatsAppNotifier notifier = new WhatsAppNotifier();
|
|
notifier.sendNotifications();
|
|
}
|
|
default -> {
|
|
}
|
|
}
|
|
if(!StatusHolder.getError() && !sql.equals("")) {
|
|
TippligaSQLConnector con = TippligaSQLConnector.getInstance();
|
|
con.executeUpdate(sql);
|
|
}
|
|
if(!StatusHolder.getError() && !beautifulInfo.equals(""))
|
|
logger.info(beautifulInfo);
|
|
}
|
|
|
|
private static void initOptions(String[] args) {
|
|
ArgumentParser parser = ArgumentParsers.newFor("tlw").build()
|
|
.defaultHelp(true)
|
|
.description("Test");
|
|
|
|
parser.addArgument("-m", "--mode")
|
|
.dest("mode")
|
|
.choices("MatchdaysUpdater", "MatchesCreatorFootball", "MatchesUpdaterFootball", "MatchesResultsUpdater", "TeamsUpdater", "APIFootballUpdater", "MatchesListGistUpdater", "PostChecksum", "WhatsAppNotifier", "SeasonPreparation")
|
|
.help("")
|
|
.required(true)
|
|
.type(String.class);
|
|
|
|
parser.addArgument("-s", "--season")
|
|
.dest("season")
|
|
.required(true)
|
|
.type(Integer.class);
|
|
|
|
parser.addArgument("-l", "--league")
|
|
.dest("league")
|
|
.required(true)
|
|
.type(Integer.class);
|
|
|
|
parser.addArgument("-c", "--configFile")
|
|
.dest("configFile")
|
|
.required(true)
|
|
.type(String.class);
|
|
|
|
Namespace res = null;
|
|
try {
|
|
res = parser.parseArgs(args);
|
|
} catch (ArgumentParserException e) {
|
|
parser.printHelp();
|
|
System.exit(1);
|
|
}
|
|
mode = res.get("mode");
|
|
season = res.get("season");
|
|
league = res.get("league");
|
|
configFile = res.get("configFile");
|
|
}
|
|
} |