Add error handling everywhere
This commit is contained in:
@@ -28,7 +28,7 @@ public class App {
|
|||||||
private static String configFile;
|
private static String configFile;
|
||||||
private static final Logger logger = LogManager.getLogger(App.class);
|
private static final Logger logger = LogManager.getLogger(App.class);
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) {
|
||||||
ConfigurationBuilder<BuiltConfiguration> builder
|
ConfigurationBuilder<BuiltConfiguration> builder
|
||||||
= ConfigurationBuilderFactory.newConfigurationBuilder();
|
= ConfigurationBuilderFactory.newConfigurationBuilder();
|
||||||
|
|
||||||
@@ -74,11 +74,11 @@ public class App {
|
|||||||
int forumId;
|
int forumId;
|
||||||
if (season == 2021) {
|
if (season == 2021) {
|
||||||
forumId = 15;
|
forumId = 15;
|
||||||
} else {
|
|
||||||
throw new Exception("Season does not exist");
|
|
||||||
}
|
|
||||||
String checksum = con.getChecksumOfPost(forumId, configFile);
|
String checksum = con.getChecksumOfPost(forumId, configFile);
|
||||||
System.out.println(checksum);
|
System.out.println(checksum);
|
||||||
|
} else {
|
||||||
|
logger.error("Season does not exist");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package de.jeyp91.apifootball;
|
|||||||
|
|
||||||
import de.jeyp91.ResourceProvider;
|
import de.jeyp91.ResourceProvider;
|
||||||
import de.jeyp91.S3Provider;
|
import de.jeyp91.S3Provider;
|
||||||
|
import de.jeyp91.teamidmatcher.TeamIDMatcher;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
@@ -15,36 +18,46 @@ import java.util.HashSet;
|
|||||||
|
|
||||||
public class APIFootballUpdater {
|
public class APIFootballUpdater {
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(APIFootballUpdater.class);
|
||||||
|
|
||||||
public APIFootballUpdater() {
|
public APIFootballUpdater() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFixtures(int league) throws Exception {
|
public void updateFixtures(int league) {
|
||||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
||||||
|
try {
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
S3Provider prov = new S3Provider();
|
S3Provider prov = new S3Provider();
|
||||||
prov.writeFixturesToS3(league, content);
|
prov.writeFixturesToS3(league, content);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAllFixtures() throws Exception {
|
public void updateAllFixtures() {
|
||||||
HashSet<Integer> leagues = getLeagues();
|
HashSet<Integer> leagues = getLeagues();
|
||||||
for (Integer league : leagues) {
|
for (Integer league : leagues) {
|
||||||
updateFixtures(league);
|
updateFixtures(league);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAllRounds() throws Exception {
|
public void updateAllRounds() {
|
||||||
HashSet<Integer> leagues = getLeagues();
|
HashSet<Integer> leagues = getLeagues();
|
||||||
for (Integer league : leagues) {
|
for (Integer league : leagues) {
|
||||||
updateRounds(league);
|
updateRounds(league);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRounds(int league) throws Exception {
|
public void updateRounds(int league) {
|
||||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
||||||
|
try {
|
||||||
String content = getRawData(apiFootballUrl);
|
String content = getRawData(apiFootballUrl);
|
||||||
S3Provider prov = new S3Provider();
|
S3Provider prov = new S3Provider();
|
||||||
prov.writeRoundsToS3(league, content);
|
prov.writeRoundsToS3(league, content);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRawData(String requestUrl) throws Exception {
|
public String getRawData(String requestUrl) throws Exception {
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import org.apache.logging.log4j.Logger;
|
|||||||
*/
|
*/
|
||||||
public class TLWMatch extends BaseMatch{
|
public class TLWMatch extends BaseMatch{
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger(TLWMatch.class);
|
|
||||||
|
|
||||||
public final Integer STATUS_NOTSTARTED = 0;
|
public final Integer STATUS_NOTSTARTED = 0;
|
||||||
public final Integer STATUS_STARTED = 1;
|
public final Integer STATUS_STARTED = 1;
|
||||||
public final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
|
public final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package de.jeyp91.tippliga;
|
package de.jeyp91.tippliga;
|
||||||
|
|
||||||
import de.jeyp91.tippligaforum.TippligaSQLConnector;
|
import de.jeyp91.tippligaforum.TippligaSQLConnector;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -9,6 +11,8 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class TLWMatchdaysUpdater {
|
public class TLWMatchdaysUpdater {
|
||||||
|
|
||||||
|
private final Logger logger = LogManager.getLogger(TLWMatch.class);
|
||||||
|
|
||||||
int season;
|
int season;
|
||||||
int league;
|
int league;
|
||||||
ArrayList<TLWMatchday> matchdaysOriginal;
|
ArrayList<TLWMatchday> matchdaysOriginal;
|
||||||
@@ -28,20 +32,20 @@ public class TLWMatchdaysUpdater {
|
|||||||
this.matchdaysUpdated.sort(Comparator.comparing(TLWMatchday::getMatchday));
|
this.matchdaysUpdated.sort(Comparator.comparing(TLWMatchday::getMatchday));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUpdateSql() throws Exception {
|
public String getUpdateSql() {
|
||||||
String updateSql = "";
|
String updateSql = "";
|
||||||
|
|
||||||
if(this.matchdaysUpdated.size() != this.matchdaysOriginal.size()) {
|
if(this.matchdaysUpdated.size() != this.matchdaysOriginal.size()) {
|
||||||
throw new Exception("Wrong matchdays config");
|
this.logger.error("Wrong matchdays config!");
|
||||||
}
|
} else {
|
||||||
|
|
||||||
for (int i = 0; i < this.matchdaysUpdated.size(); i++) {
|
for (int i = 0; i < this.matchdaysUpdated.size(); i++) {
|
||||||
TLWMatchday matchdayOriginal = this.matchdaysOriginal.get(i);
|
TLWMatchday matchdayOriginal = this.matchdaysOriginal.get(i);
|
||||||
TLWMatchday matchdayUpdated = this.matchdaysUpdated.get(i);
|
TLWMatchday matchdayUpdated = this.matchdaysUpdated.get(i);
|
||||||
|
|
||||||
if (matchdayOriginal.getMatchday() != matchdayUpdated.getMatchday()) {
|
if (matchdayOriginal.getMatchday() != matchdayUpdated.getMatchday()) {
|
||||||
throw new Exception("BUUUUG!");
|
this.logger.error("BUUUUG!");
|
||||||
}
|
} else {
|
||||||
|
|
||||||
Date now = new Date(System.currentTimeMillis());
|
Date now = new Date(System.currentTimeMillis());
|
||||||
|
|
||||||
@@ -87,7 +91,8 @@ public class TLWMatchdaysUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return updateSql;
|
return updateSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.time.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||||
private static final Logger logger = LogManager.getLogger(App.class);
|
private static final Logger logger = LogManager.getLogger(TLWMatchesUpdaterFootball.class);
|
||||||
|
|
||||||
ArrayList<TLWMatch> tlwMatchesOriginal;
|
ArrayList<TLWMatch> tlwMatchesOriginal;
|
||||||
ArrayList<TLWMatch> tlwMatchesUpdated;
|
ArrayList<TLWMatch> tlwMatchesUpdated;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class TLWTeamsUpdater {
|
|||||||
ArrayList<TLWMatch> matchesUpdated;
|
ArrayList<TLWMatch> matchesUpdated;
|
||||||
ArrayList<TLWTeam> missingTeams;
|
ArrayList<TLWTeam> missingTeams;
|
||||||
|
|
||||||
public TLWTeamsUpdater(int season, int league, String configFileName) throws Exception {
|
public TLWTeamsUpdater(int season, int league, String configFileName) {
|
||||||
|
|
||||||
TippligaSQLConnector conn = TippligaSQLConnector.getInstance();
|
TippligaSQLConnector conn = TippligaSQLConnector.getInstance();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user