Files
tlw-database-tool/src/main/java/de/jeyp91/App.java

129 lines
5.2 KiB
Java

package de.jeyp91;
import de.jeyp91.apifootball.APIFootballUpdater;
import de.jeyp91.googlecalendar.TippligaGoogleEventManager;
import de.jeyp91.tippligaforum.MatchesListForumUpdater;
import de.jeyp91.tippliga.*;
import de.jeyp91.tippligaforum.TippligaConfigProvider;
import de.jeyp91.tippligaforum.TippligaSQLConnector;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
/**
* 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 = LogManager.getLogger(App.class);
public static void main(String[] args) {
ConfigurationBuilder<BuiltConfiguration> builder
= ConfigurationBuilderFactory.newConfigurationBuilder();
RootLoggerComponentBuilder rootLogger
= builder.newRootLogger(Level.ERROR);
builder.add(rootLogger);
Configurator.initialize(builder.build());
Configurator.setRootLevel(Level.INFO);
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();
break;
case "MatchesCreatorFootball":
TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(season, league, configFile);
sql = creator.getSQLInsertString();
break;
case "MatchesUpdaterFootball":
TLWMatchesUpdaterFootball tlwMatchesUpdaterFootball = new TLWMatchesUpdaterFootball(season, league, configFile);
sql = tlwMatchesUpdaterFootball.getUpdateSQL();
beautifulInfo = tlwMatchesUpdaterFootball.getBeautifulInfo();
break;
case "TeamsUpdater":
TLWTeamsUpdater teamsUpdater = new TLWTeamsUpdater(season, league, configFile);
sql = teamsUpdater.getInsertSQL();
break;
case "APIFootballUpdater":
APIFootballUpdater apiFootballUpdater = new APIFootballUpdater();
apiFootballUpdater.updateAllFixtures(season);
apiFootballUpdater.updateAllRounds(season);
break;
case "MatchesListGistUpdater":
MatchesListForumUpdater matchesListForumUpdater = new MatchesListForumUpdater(season);
matchesListForumUpdater.updateAllLeagues(season);
break;
case "PostChecksum":
TippligaConfigProvider configProvider = new TippligaConfigProvider(season);
String checksum = configProvider.getChecksumOfConfigPost(configFile);
System.out.println(checksum);
break;
default:
break;
}
if(!StatusHolder.getError() && !sql.equals("")) {
TippligaSQLConnector con = TippligaSQLConnector.getInstance();
con.executeUpdate(sql);
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", "TeamsUpdater", "APIFootballUpdater", "MatchesListGistUpdater", "PostChecksum")
.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");
}
}