First version with ability to create database for new season
This commit is contained in:
57
src/main/java/de/jeyp91/App.java
Normal file
57
src/main/java/de/jeyp91/App.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package de.jeyp91;
|
||||
|
||||
|
||||
import de.jeyp91.tippliga.*;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
//getMatchesFromDatabase();
|
||||
//updateMatchesFromOpenLigaDB();
|
||||
//con.close();
|
||||
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
/*
|
||||
public static void getMatchesFromDatabase() throws SQLException {
|
||||
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE season = 2019 AND league = 1";
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rset = stmt.executeQuery(queryString);
|
||||
ArrayList<Match> matches = new ArrayList<Match>();
|
||||
while (rset.next()) {
|
||||
matches.add(new Match(rset));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public static void updateMatchesFromOpenLigaDB() throws Exception {
|
||||
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE season = 2018 AND league = 48";
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rset = stmt.executeQuery(queryString);
|
||||
ArrayList<Match> matchesTLW = new ArrayList<Match>();
|
||||
while (rset.next()) {
|
||||
matchesTLW.add(new Match(rset));
|
||||
}
|
||||
|
||||
// Download data from OpenLigaDB
|
||||
JSONArray matchDBJson = new JSONArray();
|
||||
OpenLigaDB openLigaDB = new OpenLigaDB();
|
||||
for (int i = 1; i <= 6; i++) {
|
||||
// matchDBJson.put(OpenLigaDB.downloadMatchday(2020, "bl1", i));
|
||||
// matchDBJson.put(OpenLigaDB.downloadMatchday(2020, "bl2", i));
|
||||
// matchDBJson.put(OpenLigaDB.downloadMatchday(2020, "bl3", i));
|
||||
matchDBJson.add(openLigaDB.getMatchesOfMatchdayAsJSONArray(2018, "dfb", i));
|
||||
}
|
||||
|
||||
for (Match match : matchesTLW) {
|
||||
match.updateDataFromOpenLigaDb(matchDBJson);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
40
src/main/java/de/jeyp91/BaseMatch.java
Normal file
40
src/main/java/de/jeyp91/BaseMatch.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package de.jeyp91;
|
||||
|
||||
public abstract class BaseMatch {
|
||||
|
||||
public final Integer COMPARISON_IDENTICAL = 0;
|
||||
public final Integer COMPARISON_DIFFERENT = 1;
|
||||
public final Integer COMPARISON_DIFFERENT_DATETIME = 2;
|
||||
public final Integer COMPARISON_DIFFERENT_RESULT = 3;
|
||||
|
||||
protected Integer teamIdHome;
|
||||
protected Integer teamIdGuest;
|
||||
protected Integer goalsHome = null;
|
||||
protected Integer goalsGuest = null;
|
||||
protected Integer matchday = null;
|
||||
protected String matchDatetime = null;
|
||||
|
||||
public Integer getMatchday() {
|
||||
return this.matchday;
|
||||
}
|
||||
|
||||
public Integer getTeamIdHome() {
|
||||
return this.teamIdHome;
|
||||
}
|
||||
|
||||
public Integer getTeamIdGuest() {
|
||||
return this.teamIdGuest;
|
||||
}
|
||||
|
||||
public String getMatchDateTime() {
|
||||
return this.matchDatetime;
|
||||
}
|
||||
|
||||
public Integer getGoalsHome() {
|
||||
return this.goalsHome;
|
||||
}
|
||||
|
||||
public Integer getGoalsGuest() {
|
||||
return this.goalsGuest;
|
||||
}
|
||||
}
|
||||
96
src/main/java/de/jeyp91/MatchUtils.java
Normal file
96
src/main/java/de/jeyp91/MatchUtils.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package de.jeyp91;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class MatchUtils {
|
||||
|
||||
/*
|
||||
|
||||
public void updateDataFromOpenLigaDb(JSONArray openLigaDbData) throws Exception {
|
||||
loopOverAllMatchdays:
|
||||
for(int i = 0; i < openLigaDbData.size(); i++) {
|
||||
for(int j = 0; j < ((JSONArray)(openLigaDbData.get(i))).size(); j++) {
|
||||
Match tempMatch = new Match(this.season, this.league, this.matchday, this.matchNo, (JSONObject)(((JSONArray)openLigaDbData.get(i)).get(j)));
|
||||
if(isSameMatch(tempMatch)) {
|
||||
break loopOverAllMatchdays;
|
||||
}
|
||||
updateDateTime(tempMatch);
|
||||
updateResult(tempMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateDateTime(Match compareMatch) {
|
||||
if(!this.getSeason().equals(compareMatch.getSeason())) {
|
||||
return false;
|
||||
}
|
||||
if(!this.getLeague().equals(compareMatch.getLeague())) {
|
||||
return false;
|
||||
}
|
||||
if(!this.getMatchday().equals(compareMatch.getMatchday())) {
|
||||
return false;
|
||||
}
|
||||
if(this.getTeamIdHome() == null || compareMatch.getTeamIdHome() == null
|
||||
|| (this.getTeamIdHome() != compareMatch.getTeamIdHome())) {
|
||||
return false;
|
||||
}
|
||||
if(this.getTeamIdGuest() == null || compareMatch.getTeamIdGuest() == null
|
||||
|| (this.getTeamIdGuest() != compareMatch.getTeamIdGuest())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String thisDateTime = this.getMatchDateTime().replace("T", " ");
|
||||
String tempDateTime = compareMatch.getMatchDateTime().replace("T", " ");
|
||||
if(!tempDateTime.equals(thisDateTime)) {
|
||||
// System.out.println(String.valueOf(this.matchNo) + ":");
|
||||
// System.out.println("Old date: " + thisDateTime + "; New date: " + tempDateTime);
|
||||
// System.out.println();
|
||||
|
||||
// String updateQuery = "UPDATE phpbb_footb_matches SET match_datetime = '" + tempDateTime + "' WHERE season = " + this.season + " AND league = " + this.league + " AND match_no = " + this.matchNo + " AND team_id_home = " + this.teamIdHome + " AND team_id_guest = " + this.teamIdGuest + " AND match_datetime = '" + this.matchDatetime + "';";
|
||||
// System.out.println(updateQuery);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateResult(Match compareMatch) {
|
||||
if(!this.getSeason().equals(compareMatch.getSeason())) {
|
||||
return false;
|
||||
}
|
||||
if(!this.getLeague().equals(compareMatch.getLeague())) {
|
||||
return false;
|
||||
}
|
||||
if(!this.getMatchday().equals(compareMatch.getMatchday())) {
|
||||
return false;
|
||||
}
|
||||
if(this.getTeamIdHome() == null || compareMatch.getTeamIdHome() == null
|
||||
|| (this.getTeamIdHome() != compareMatch.getTeamIdHome())) {
|
||||
return false;
|
||||
}
|
||||
if(this.getTeamIdGuest() == null || compareMatch.getTeamIdGuest() == null
|
||||
|| (this.getTeamIdGuest() != compareMatch.getTeamIdGuest())) {
|
||||
return false;
|
||||
}
|
||||
String thisDateTime = this.getMatchDateTime().replace("T", " ");
|
||||
String tempDateTime = compareMatch.getMatchDateTime().replace("T", " ");
|
||||
if(!tempDateTime.equals(thisDateTime)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(this.goalsHome != compareMatch.goalsHome ||
|
||||
this.goalsGuest != compareMatch.goalsGuest &&
|
||||
this.goalsHome != null && this.goalsGuest != null && compareMatch.goalsHome != null && compareMatch.goalsGuest != null) {
|
||||
String oldResult = String.valueOf(this.goalsHome) + " : " + String.valueOf(this.goalsGuest);
|
||||
String newResult = String.valueOf(compareMatch.goalsHome) + " : " + String.valueOf(compareMatch.goalsGuest);
|
||||
|
||||
System.out.println(String.valueOf(this.matchNo) + ":");
|
||||
System.out.println(this.matchDatetime + " Old result: " + oldResult + "; New result: " + newResult);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
65
src/main/java/de/jeyp91/TeamIDMatcher.java
Normal file
65
src/main/java/de/jeyp91/TeamIDMatcher.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package de.jeyp91;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.io.Resources;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
public class TeamIDMatcher {
|
||||
|
||||
private static HashBiMap<Integer, Integer> ids = null;
|
||||
|
||||
private static void initBiMap() {
|
||||
ids = HashBiMap.create();
|
||||
JSONArray teams = null;
|
||||
URL url = Resources.getResource("Team_ID_TLW_APIF_config.json");
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
teams = (JSONArray) jsonParser.parse(jsonConfig);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(Object team:teams) {
|
||||
int tippligaID = ((Long)((JSONObject) team).get("tippligaID")).intValue();
|
||||
int openligaDBID = ((Long) ((JSONObject) team).get("apiFootballID")).intValue();
|
||||
ids.put(tippligaID, openligaDBID);
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getOpenLigaDbIdFromTippligaId(int id) {
|
||||
if(ids == null) {
|
||||
initBiMap();
|
||||
}
|
||||
if(ids.containsKey(id)) {
|
||||
return ids.get(id);
|
||||
} else {
|
||||
// System.out.println("ID: " + String.valueOf(id) + " not in ID Matcher.");
|
||||
System.out.println(String.valueOf(id));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getTippligaIdFromOpenLigaDbId(Integer id) {
|
||||
if(id == null) return null;
|
||||
if(ids == null) {
|
||||
initBiMap();
|
||||
}
|
||||
if(ids.inverse().containsKey(id)) {
|
||||
return ids.inverse().get(id);
|
||||
} else {
|
||||
System.out.println("ID: " + String.valueOf(id) + " not in ID Matcher.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
70
src/main/java/de/jeyp91/TeamValidator.java
Normal file
70
src/main/java/de/jeyp91/TeamValidator.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package de.jeyp91;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import de.jeyp91.tippliga.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TeamValidator {
|
||||
|
||||
private final int INCONSISTENT_TEAM_ID = 0;
|
||||
private final int INCONSISTENT_TEAM_NAME = 1;
|
||||
private final int INCONSISTENT_TEAM_NAME_SHORT = 2;
|
||||
private final int INCONSISTENT_TEAM_SYMBOL = 3;
|
||||
|
||||
private ArrayList<TLWTeam> teams;
|
||||
|
||||
public TeamValidator(ArrayList<TLWTeam> teams) {
|
||||
this.teams = teams;
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
ArrayList<TLWTeam> tempTeams = teams;
|
||||
while(tempTeams.size() > 0) {
|
||||
TLWTeam referenceTeam = tempTeams.get(0);
|
||||
tempTeams.remove(0);
|
||||
|
||||
ArrayList<TLWTeam> finishedTeams = new ArrayList<TLWTeam>();
|
||||
for (TLWTeam team : tempTeams) {
|
||||
if(referenceTeam.getTeamSymbol().equals(team.getTeamSymbol()) && !referenceTeam.getTeamSymbol().equals("blank.gif")) {
|
||||
finishedTeams.add(team);
|
||||
compareTeams(referenceTeam, team);
|
||||
}
|
||||
}
|
||||
|
||||
for (TLWTeam team : finishedTeams) {
|
||||
tempTeams.remove(team);
|
||||
}
|
||||
}
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
private int compareTeams(TLWTeam team1, TLWTeam team2) {
|
||||
if(team1.getTeamId() != team2.getTeamId()) {
|
||||
// System.out.println("Team ID wrong" + team1.getTeamId() + " " + team2.getTeamId());
|
||||
String update = "UPDATE phpbb_footb_teams SET team_id = " + String.valueOf(team1.getTeamId()) + " WHERE team_name = '" + team1.getTeamName() + "' AND team_name_short = '" + team1.getTeamNameShort() + "' AND team_symbol = '" + team1.getTeamSymbol() + "';";
|
||||
System.out.println(update);
|
||||
return INCONSISTENT_TEAM_ID;
|
||||
}
|
||||
if(!team1.getTeamName().equals(team2.getTeamName())) {
|
||||
// System.out.println("Team Name wrong: " + team1.getTeamName() + " " + team2.getTeamName());
|
||||
String update = "UPDATE phpbb_footb_teams SET team_name = '" + team1.getTeamName() + "' WHERE team_id = " + String.valueOf(team1.getTeamId()) + " AND team_name_short = '" + team1.getTeamNameShort() + "' AND team_symbol = '" + team1.getTeamSymbol() + "';";
|
||||
System.out.println(update);
|
||||
return INCONSISTENT_TEAM_NAME;
|
||||
}
|
||||
if(!team1.getTeamNameShort().equals(team2.getTeamNameShort())) {
|
||||
// System.out.println("Team Name Short wrong: " + team1.getTeamNameShort() + " " + team2.getTeamNameShort());
|
||||
String update = "UPDATE phpbb_footb_teams SET team_name_short = '" + team1.getTeamNameShort() + "' WHERE team_id = " + String.valueOf(team1.getTeamId()) + " AND team_name = '" + team1.getTeamName() + "' AND team_symbol = '" + team1.getTeamSymbol() + "';";
|
||||
System.out.println(update);
|
||||
return INCONSISTENT_TEAM_NAME_SHORT;
|
||||
}
|
||||
if(!team1.getTeamSymbol().equals(team2.getTeamSymbol())) {
|
||||
// System.out.println("Team Symbol wrong: " + team1.getTeamSymbol() + " " + team2.getTeamSymbol());
|
||||
String update = "UPDATE phpbb_footb_teams SET team_symbol = '" + team1.getTeamSymbol() + "' WHERE team_id = " + String.valueOf(team1.getTeamId()) + " AND team_name = '" + team1.getTeamName() + "' AND team_name_short = '" + team1.getTeamNameShort() + "';";
|
||||
System.out.println(update);
|
||||
return INCONSISTENT_TEAM_SYMBOL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
170
src/main/java/de/jeyp91/apifootball/APIFootballConnector.java
Normal file
170
src/main/java/de/jeyp91/apifootball/APIFootballConnector.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package de.jeyp91.apifootball;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class APIFootballConnector {
|
||||
|
||||
private final String API_FOOTBALL_URL = "https://v2.api-football.com/";
|
||||
private int season;
|
||||
|
||||
public APIFootballConnector(int season) {
|
||||
this.season = season;
|
||||
}
|
||||
|
||||
public APIFootballMatch getMatchDataByLeagueAndMatchID(int league, int id) {
|
||||
|
||||
APIFootballMatch matchWithID = null;
|
||||
|
||||
ArrayList<APIFootballMatch> allMatches = getMatchesFromLeagueFromFile(league);
|
||||
for (APIFootballMatch singleMatch : allMatches) {
|
||||
if (singleMatch.getAPIFootBallMatchID() == id) {
|
||||
matchWithID = singleMatch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matchWithID;
|
||||
}
|
||||
|
||||
public ArrayList<APIFootballMatch> getMatchDataByLeagueAndMatchday(int league, int matchday) {
|
||||
|
||||
ArrayList<APIFootballMatch> matchesOfMatchday = new ArrayList<>();
|
||||
|
||||
ArrayList<APIFootballMatch> allMatches = getMatchesFromLeagueFromFile(league);
|
||||
for (APIFootballMatch singleMatch : allMatches) {
|
||||
if (singleMatch.getMatchday() == matchday) {
|
||||
matchesOfMatchday.add(singleMatch);
|
||||
}
|
||||
}
|
||||
|
||||
return matchesOfMatchday;
|
||||
}
|
||||
|
||||
private ArrayList<APIFootballMatch> getMatchesFromLeagueFromFile(int id) {
|
||||
ArrayList<APIFootballMatch> matchesList = new ArrayList<>();
|
||||
|
||||
JSONObject matches = readFromFile("matches_league_" + id);
|
||||
JSONArray matchArray = (JSONArray) (((JSONObject)matches.get("api")).get("fixtures"));
|
||||
|
||||
for(int i = 0; i < matchArray.size(); i++) {
|
||||
matchesList.add(new APIFootballMatch((JSONObject) matchArray.get(i), this.season));
|
||||
}
|
||||
|
||||
return matchesList;
|
||||
}
|
||||
|
||||
private JSONObject readFromFile(String filename) {
|
||||
|
||||
JSONObject object = null;
|
||||
//JSON parser object to parse read file
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename + ".json");
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
//Read JSON file
|
||||
object = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
private JSONArray getDataAsJSONArray(String requestUrl) {
|
||||
|
||||
String rawData = getRawData(requestUrl);
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONArray data = null;
|
||||
try {
|
||||
data = (JSONArray) parser.parse(rawData);
|
||||
} catch (ParseException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private JSONObject getDataAsJSONObject(String requestUrl) {
|
||||
|
||||
String rawData = getRawData(requestUrl);
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject data = null;
|
||||
try {
|
||||
data = (JSONObject) parser.parse(rawData);
|
||||
} catch (ParseException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
String getRawData(String requestUrl) {
|
||||
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
HttpGet request = new HttpGet(requestUrl);
|
||||
|
||||
// add request header
|
||||
request.addHeader("Content-Type", "application/json");
|
||||
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
response = client.execute(request);
|
||||
} catch (ClientProtocolException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
rd = new BufferedReader(
|
||||
new InputStreamReader(response.getEntity().getContent())
|
||||
);
|
||||
} catch (IOException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line = "";
|
||||
while (true) {
|
||||
try {
|
||||
line = rd.readLine();
|
||||
} catch (IOException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Stop reading if last line was found.
|
||||
if (line == null) break;
|
||||
|
||||
result.append(line);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
76
src/main/java/de/jeyp91/apifootball/APIFootballMatch.java
Normal file
76
src/main/java/de/jeyp91/apifootball/APIFootballMatch.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package de.jeyp91.apifootball;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import de.jeyp91.BaseMatch;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class APIFootballMatch extends BaseMatch {
|
||||
|
||||
private int season;
|
||||
private int matchId;
|
||||
private int leagueId;
|
||||
private String matchStatus;
|
||||
|
||||
public APIFootballMatch(JSONObject json, int season) {
|
||||
this.season = season;
|
||||
this.matchId = Integer.parseInt(json.get("fixture_id").toString());
|
||||
// TODO
|
||||
this.leagueId = Integer.parseInt(json.get("league_id").toString());
|
||||
this.teamIdHome = Integer.parseInt(((JSONObject) json.get("homeTeam")).get("team_id").toString());
|
||||
this.teamIdGuest = Integer.parseInt(((JSONObject) json.get("awayTeam")).get("team_id").toString());
|
||||
this.goalsHome = getNumberOrNull(json.get("goalsHomeTeam"));
|
||||
this.goalsGuest = getNumberOrNull(json.get("goalsAwayTeam"));
|
||||
this.matchday = getMatchdayFromRoundString(json.get("round").toString(), this.leagueId);
|
||||
this.matchStatus = json.get("statusShort").toString();
|
||||
this.matchDatetime = (String) json.get("event_date");
|
||||
}
|
||||
|
||||
public int getAPIFootBallMatchID() {
|
||||
return this.matchId;
|
||||
}
|
||||
|
||||
private int getMatchdayFromRoundString(String round, int leagueId) {
|
||||
round = round.replace(" ", "_");
|
||||
Integer matchday = null;
|
||||
JSONObject roundsObject = readFromFile("rounds_" + leagueId + ".json");
|
||||
JSONArray roundsArray = (JSONArray)(((JSONObject) roundsObject.get("api")).get("fixtures"));
|
||||
for (int i = 0; i < roundsArray.size(); i++) {
|
||||
if(roundsArray.get(i).toString().equals(round)) {
|
||||
matchday = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return matchday;
|
||||
}
|
||||
|
||||
private JSONObject readFromFile(String filename) {
|
||||
|
||||
JSONObject object = null;
|
||||
//JSON parser object to parse read file
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename);
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
//Read JSON file
|
||||
object = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
private Integer getNumberOrNull(Object object) {
|
||||
return object != null ? Integer.parseInt(object.toString()) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.jeyp91.googlecalendar;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class CalendarConfigProvider {
|
||||
|
||||
private static JSONObject googleCalendarConfig = null;
|
||||
|
||||
private static JSONObject getGoogleCalendarConfig() {
|
||||
if(googleCalendarConfig == null) {
|
||||
//JSON parser object to parse read file
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource("Google_Calendar_Config.json");
|
||||
String jsonConfig = null;
|
||||
|
||||
try {
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
//Read JSON file
|
||||
googleCalendarConfig = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return googleCalendarConfig;
|
||||
}
|
||||
|
||||
public static String getCalendarUrl(int league) {
|
||||
|
||||
// Overwrite league from 2 to 1 because they share one calendar
|
||||
league = league == 2 ? 1 : league;
|
||||
|
||||
JSONObject leagueConfig = (JSONObject) getGoogleCalendarConfig().get(String.valueOf(league));
|
||||
return (String) leagueConfig.get("url");
|
||||
}
|
||||
|
||||
public static String getCalendarId(int league) {
|
||||
|
||||
// Overwrite league from 2 to 1 because they share one calendar
|
||||
league = league == 2 ? 1 : league;
|
||||
|
||||
JSONObject leagueConfig = (JSONObject) getGoogleCalendarConfig().get(String.valueOf(league));
|
||||
return (String) leagueConfig.get("id");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Google Inc.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package de.jeyp91.googlecalendar;
|
||||
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.HttpHeaders;
|
||||
import com.google.api.services.calendar.Calendar;
|
||||
import com.google.api.services.calendar.CalendarScopes;
|
||||
import com.google.api.services.calendar.model.Event;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A sample that demonstrates how to update a
|
||||
* <a href="https://developers.google.com/google-apps/calendar/v3/reference/">Calendar resource</a>
|
||||
* safely, ensuring that other changes aren't overwritten. It does this by passing along the etag of
|
||||
* the resource being updated in the "If-Match" HTTP header of the request, which will cause the
|
||||
* request to fail if the version on the server is different.
|
||||
*
|
||||
* @author ekoleda+devrel@google.com (Eric Koleda)
|
||||
*/
|
||||
public class ConditionalModificationSample {
|
||||
|
||||
/** The maximum number of times to attempt to update the event, before aborting. */
|
||||
private static final int MAX_UPDATE_ATTEMPTS = 5;
|
||||
|
||||
/** Global instance of the Calendar client. */
|
||||
private static Calendar client;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
List<String> scopes = Lists.newArrayList(CalendarScopes.CALENDAR);
|
||||
client = Utils.createCalendarClient(scopes);
|
||||
run();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test event, pauses while the user modifies the event in the Calendar UI, and then
|
||||
* updates the event with a new location, ensure that the user's changes aren't overwritten.
|
||||
*/
|
||||
private static void run() throws IOException {
|
||||
// Create a test event.
|
||||
Event event = Utils.createTestEvent(client, "Test Event");
|
||||
System.out.println(String.format("Event created: %s", event.getHtmlLink()));
|
||||
|
||||
// Pause while the user modifies the event in the Calendar UI.
|
||||
System.out.println("Modify the event's description and hit enter to continue.");
|
||||
System.in.read();
|
||||
|
||||
// Modify the local copy of the event.
|
||||
event.setSummary("Updated Test Event");
|
||||
|
||||
// Update the event, making sure that we don't overwrite other changes.
|
||||
int numAttempts = 0;
|
||||
boolean isUpdated = false;
|
||||
do {
|
||||
Calendar.Events.Update request = client.events().update("primary", event.getId(), event);
|
||||
request.setRequestHeaders(new HttpHeaders().setIfMatch(event.getEtag()));
|
||||
try {
|
||||
event = request.execute();
|
||||
isUpdated = true;
|
||||
} catch (GoogleJsonResponseException e) {
|
||||
if (e.getStatusCode() == 412) {
|
||||
// A 412 status code, "Precondition failed", indicates that the etag values didn't
|
||||
// match, and the event was updated on the server since we last retrieved it. Use
|
||||
// {@link Calendar.Events.Get} to retrieve the latest version.
|
||||
Event latestEvent = client.events().get("primary", event.getId()).execute();
|
||||
|
||||
// You may want to have more complex logic here to resolve conflicts. In this sample we're
|
||||
// simply overwriting the summary.
|
||||
latestEvent.setSummary(event.getSummary());
|
||||
event = latestEvent;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
numAttempts++;
|
||||
} while (!isUpdated && numAttempts <= MAX_UPDATE_ATTEMPTS);
|
||||
|
||||
if (isUpdated) {
|
||||
System.out.println("Event updated.");
|
||||
} else {
|
||||
System.out.println(String.format("Failed to update event after %d attempts.", numAttempts));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Google Inc.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package de.jeyp91.googlecalendar;
|
||||
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.HttpHeaders;
|
||||
import com.google.api.services.calendar.Calendar;
|
||||
import com.google.api.services.calendar.CalendarScopes;
|
||||
import com.google.api.services.calendar.model.Event;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A sample that demonstrates how to determine if a
|
||||
* <a href="https://developers.google.com/google-apps/calendar/v3/reference/">Calendar resource</a>
|
||||
* has been modified since you last retrieved it. It does this by passing along the etag of the
|
||||
* resource being retrieved in the "If-None-Match" HTTP header of the request, which will cause the
|
||||
* request to fail if the version on the server is the same as the local version.
|
||||
*
|
||||
* @author ekoleda+devrel@google.com (Eric Koleda)
|
||||
*/
|
||||
public class ConditionalRetrievalSample {
|
||||
|
||||
/** Global instance of the Calendar client. */
|
||||
private static Calendar client;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
List<String> scopes = Lists.newArrayList(CalendarScopes.CALENDAR);
|
||||
client = Utils.createCalendarClient(scopes);
|
||||
run();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test event, pauses while the user modifies the event in the Calendar UI, and then
|
||||
* checks if the event has been modified.
|
||||
*/
|
||||
private static void run() throws IOException {
|
||||
// Create a test event.
|
||||
Event event = Utils.createTestEvent(client, "Test Event");
|
||||
System.out.println(String.format("Event created: %s", event.getHtmlLink()));
|
||||
|
||||
// Pause while the user modifies the event in the Calendar UI.
|
||||
System.out.println("Modify the event's description and hit enter to continue.");
|
||||
System.in.read();
|
||||
|
||||
// Fetch the event again if it's been modified.
|
||||
Calendar.Events.Get getRequest = client.events().get("primary", event.getId());
|
||||
getRequest.setRequestHeaders(new HttpHeaders().setIfNoneMatch(event.getEtag()));
|
||||
try {
|
||||
event = getRequest.execute();
|
||||
System.out.println("The event was modified, retrieved latest version.");
|
||||
} catch (GoogleJsonResponseException e) {
|
||||
if (e.getStatusCode() == 304) {
|
||||
// A 304 status code, "Not modified", indicates that the etags match, and the event has
|
||||
// not been modified since we last retrieved it.
|
||||
System.out.println("The event was not modified, using local version.");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package de.jeyp91.googlecalendar;
|
||||
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.DateTime;
|
||||
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||
import com.google.api.services.calendar.CalendarScopes;
|
||||
import com.google.api.services.calendar.Calendar;
|
||||
import com.google.api.services.calendar.model.Event;
|
||||
import com.google.api.services.calendar.model.EventDateTime;
|
||||
import com.google.api.services.calendar.model.EventReminder;
|
||||
import com.google.api.services.calendar.model.Events;
|
||||
import de.jeyp91.tippliga.TLWLeague;
|
||||
import de.jeyp91.tippliga.TLWMatchday;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GoogleCalendarConnector {
|
||||
private static final String APPLICATION_NAME = "Google Calendar API Java Quickstart";
|
||||
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||
private static final String TOKENS_DIRECTORY_PATH = "tokens";
|
||||
|
||||
/**
|
||||
* Global instance of the scopes required by this quickstart.
|
||||
* If modifying these scopes, delete your previously saved tokens/ folder.
|
||||
*/
|
||||
private static final List<String> SCOPES = Collections.singletonList(CalendarScopes.CALENDAR_READONLY);
|
||||
private static final String CREDENTIALS_FILE_PATH = "/Google_Credentials.json";
|
||||
|
||||
/**
|
||||
* Creates an authorized Credential object.
|
||||
* @param HTTP_TRANSPORT The network HTTP Transport.
|
||||
* @return An authorized Credential object.
|
||||
* @throws IOException If the Google_Credentials.json file cannot be found.
|
||||
*/
|
||||
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
|
||||
// Load client secrets.
|
||||
InputStream in = GoogleCalendarConnector.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
|
||||
if (in == null) {
|
||||
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
|
||||
}
|
||||
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
|
||||
|
||||
// Build flow and trigger user authorization request.
|
||||
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
|
||||
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
|
||||
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
|
||||
.setAccessType("offline")
|
||||
.build();
|
||||
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
|
||||
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
|
||||
}
|
||||
|
||||
private static com.google.api.services.calendar.Calendar getSerivce() {
|
||||
|
||||
com.google.api.services.calendar.Calendar service = null;
|
||||
|
||||
final NetHttpTransport HTTP_TRANSPORT;
|
||||
try {
|
||||
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
|
||||
service = new com.google.api.services.calendar.Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
|
||||
.setApplicationName(APPLICATION_NAME)
|
||||
.build();
|
||||
|
||||
|
||||
} catch (GeneralSecurityException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
public static List<Event> getAllEventsStartingFromDateTime(int league, DateTime dateTime) {
|
||||
|
||||
com.google.api.services.calendar.Calendar service = getSerivce();
|
||||
Events events = null;
|
||||
|
||||
String calendarUrl = CalendarConfigProvider.getCalendarUrl(league);
|
||||
|
||||
// Build a new authorized API client service.
|
||||
try {
|
||||
events = service.events().list(calendarUrl)
|
||||
.setMaxResults(100)
|
||||
.setTimeMin(dateTime)
|
||||
.setOrderBy("startTime")
|
||||
.setSingleEvents(true)
|
||||
.execute();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// List the next 10 events from the primary calendar.
|
||||
assert events != null;
|
||||
List<Event> items = events.getItems();
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public static void createNewEvent(TLWMatchday matchday) {
|
||||
Calendar service = getSerivce();
|
||||
|
||||
String calendarId = CalendarConfigProvider.getCalendarId(matchday.getLeague());
|
||||
|
||||
String matchdayName = matchday.getMatchdayName() == "" ? matchday.getMatchday().toString() + ". Spieltag" : matchday.getMatchdayName();
|
||||
String summary = "Tippabgabeschluss " + TLWLeague.getLeagueNameCalendar(matchday.getLeague()) + " " + matchdayName;
|
||||
String description = "Tippabgabeschluss " + TLWLeague.getLeagueNameCalendar(matchday.getLeague()) + " " + matchdayName;
|
||||
|
||||
Event event = new Event()
|
||||
.setSummary(summary)
|
||||
.setLocation("https://www.tippliga-wuerzburg.de/app.php/football/bet")
|
||||
.setDescription(description);
|
||||
|
||||
DateTime deliveryDate = new DateTime(matchday.getDeliveryDate().replace(" ", "T"));
|
||||
EventDateTime date = new EventDateTime()
|
||||
.setDateTime(deliveryDate)
|
||||
.setTimeZone("Europe/Berlin");
|
||||
event.setStart(date);
|
||||
event.setEnd(date);
|
||||
|
||||
// Set reminder to 12 hours before
|
||||
Event.Reminders reminders = new Event.Reminders();
|
||||
EventReminder[] reminderOverrides = new EventReminder[] {
|
||||
new EventReminder().setMethod("popup").setMinutes(12 * 60),
|
||||
};
|
||||
reminders.setOverrides(Arrays.asList(reminderOverrides));
|
||||
event.setReminders(reminders);
|
||||
|
||||
try {
|
||||
service.events().insert(calendarId, event).execute();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateMatchdayDate(TLWMatchday matchday) {
|
||||
|
||||
}
|
||||
|
||||
public static Event getEventForMatchday(TLWMatchday matchday) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
140
src/main/java/de/jeyp91/googlecalendar/SyncTokenSample.java
Normal file
140
src/main/java/de/jeyp91/googlecalendar/SyncTokenSample.java
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Google Inc.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package de.jeyp91.googlecalendar;
|
||||
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.util.DateTime;
|
||||
import com.google.api.client.util.store.DataStore;
|
||||
import com.google.api.services.calendar.Calendar;
|
||||
import com.google.api.services.calendar.CalendarScopes;
|
||||
import com.google.api.services.calendar.model.Event;
|
||||
import com.google.api.services.calendar.model.Events;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* A sample that demonstrates how to efficiently sync
|
||||
* <a href="https://developers.google.com/google-apps/calendar/v3/reference/">Calendar resource</a>
|
||||
* using sync tokens.
|
||||
*
|
||||
* @author ekoleda+devrel@google.com (Eric Koleda)
|
||||
*/
|
||||
public class SyncTokenSample {
|
||||
|
||||
/** Global instance of the Calendar client. */
|
||||
private static Calendar client;
|
||||
|
||||
/** Global instance of the event datastore. */
|
||||
private static DataStore<String> eventDataStore;
|
||||
|
||||
/** Global instance of the sync settings datastore. */
|
||||
private static DataStore<String> syncSettingsDataStore;
|
||||
|
||||
/** The key in the sync settings datastore that holds the current sync token. */
|
||||
private static final String SYNC_TOKEN_KEY = "syncToken";
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
List<String> scopes = Lists.newArrayList(CalendarScopes.CALENDAR_READONLY);
|
||||
client = Utils.createCalendarClient(scopes);
|
||||
eventDataStore = Utils.getDataStoreFactory().getDataStore("EventStore");
|
||||
syncSettingsDataStore = Utils.getDataStoreFactory().getDataStore("SyncSettings");
|
||||
run();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs events from the user's primary calendar to a local datastore. A full sync is performed on
|
||||
* the first run, with incremental syncs on subsequent runs.
|
||||
*/
|
||||
private static void run() throws IOException {
|
||||
// Construct the {@link Calendar.Events.List} request, but don't execute it yet.
|
||||
Calendar.Events.List request = client.events().list("primary");
|
||||
|
||||
// Load the sync token stored from the last execution, if any.
|
||||
String syncToken = syncSettingsDataStore.get(SYNC_TOKEN_KEY);
|
||||
if (syncToken == null) {
|
||||
System.out.println("Performing full sync.");
|
||||
|
||||
// Set the filters you want to use during the full sync. Sync tokens aren't compatible with
|
||||
// most filters, but you may want to limit your full sync to only a certain date range.
|
||||
// In this example we are only syncing events up to a year old.
|
||||
Date oneYearAgo = Utils.getRelativeDate(java.util.Calendar.YEAR, -1);
|
||||
request.setTimeMin(new DateTime(oneYearAgo, TimeZone.getTimeZone("UTC")));
|
||||
} else {
|
||||
System.out.println("Performing incremental sync.");
|
||||
request.setSyncToken(syncToken);
|
||||
}
|
||||
|
||||
// Retrieve the events, one page at a time.
|
||||
String pageToken = null;
|
||||
Events events = null;
|
||||
do {
|
||||
request.setPageToken(pageToken);
|
||||
|
||||
try {
|
||||
events = request.execute();
|
||||
} catch (GoogleJsonResponseException e) {
|
||||
if (e.getStatusCode() == 410) {
|
||||
// A 410 status code, "Gone", indicates that the sync token is invalid.
|
||||
System.out.println("Invalid sync token, clearing event store and re-syncing.");
|
||||
syncSettingsDataStore.delete(SYNC_TOKEN_KEY);
|
||||
eventDataStore.clear();
|
||||
run();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
List<Event> items = events.getItems();
|
||||
if (items.size() == 0) {
|
||||
System.out.println("No new events to sync.");
|
||||
} else {
|
||||
for (Event event : items) {
|
||||
syncEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
pageToken = events.getNextPageToken();
|
||||
} while (pageToken != null);
|
||||
|
||||
// Store the sync token from the last request to be used during the next execution.
|
||||
syncSettingsDataStore.set(SYNC_TOKEN_KEY, events.getNextSyncToken());
|
||||
|
||||
System.out.println("Sync complete.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync an individual event. In this example we simply store it's string represenation to a file
|
||||
* system data store.
|
||||
*/
|
||||
private static void syncEvent(Event event) throws IOException {
|
||||
if ("cancelled".equals(event.getStatus()) && eventDataStore.containsKey(event.getId())) {
|
||||
eventDataStore.delete(event.getId());
|
||||
System.out.println(String.format("Deleting event: ID=%s", event.getId()));
|
||||
} else {
|
||||
eventDataStore.set(event.getId(), event.toString());
|
||||
System.out.println(
|
||||
String.format("Syncing event: ID=%s, Name=%s", event.getId(), event.getSummary()));
|
||||
}
|
||||
}
|
||||
}
|
||||
130
src/main/java/de/jeyp91/googlecalendar/Utils.java
Normal file
130
src/main/java/de/jeyp91/googlecalendar/Utils.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Google Inc.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package de.jeyp91.googlecalendar;
|
||||
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.DateTime;
|
||||
import com.google.api.client.util.store.DataStoreFactory;
|
||||
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||
import com.google.api.services.calendar.Calendar;
|
||||
import com.google.api.services.calendar.model.Event;
|
||||
import com.google.api.services.calendar.model.Event.Reminders;
|
||||
import com.google.api.services.calendar.model.EventDateTime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* A collection of utility methods used by these samples.
|
||||
*/
|
||||
public class Utils {
|
||||
/** Application name */
|
||||
private static final String APPLICATION_NAME = "Calendar Sync Samples";
|
||||
|
||||
/** Directory to store user credentials. */
|
||||
private static final java.io.File DATA_STORE_DIR =
|
||||
new java.io.File(System.getProperty("user.home"), ".store/calendar-sync");
|
||||
|
||||
/** Global instance of the {@link DataStoreFactory}. */
|
||||
private static FileDataStoreFactory dataStoreFactory;
|
||||
|
||||
/** Global instance of the JSON factory. */
|
||||
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||
|
||||
/** Global instance of the HTTP transport. */
|
||||
private static HttpTransport httpTransport;
|
||||
|
||||
static {
|
||||
try {
|
||||
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a new Calendar client to use when making requests to the API. */
|
||||
public static Calendar createCalendarClient(List<String> scopes) throws Exception {
|
||||
Credential credential = authorize(scopes);
|
||||
return new Calendar.Builder(
|
||||
httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
|
||||
}
|
||||
|
||||
/** Authorizes the installed application to access user's protected data. */
|
||||
public static Credential authorize(List<String> scopes) throws Exception {
|
||||
// Load client secrets.
|
||||
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
|
||||
new InputStreamReader(SyncTokenSample.class.getResourceAsStream("/client_secrets.json")));
|
||||
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|
||||
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter")) {
|
||||
System.out.println(
|
||||
"Overwrite the src/main/resources/client_secrets.json file with the client secrets file "
|
||||
+ "you downloaded from your Google Developers Console project.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport,
|
||||
JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build();
|
||||
// Authorize.
|
||||
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
|
||||
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
|
||||
}
|
||||
|
||||
/** Gets the datastore factory used in these samples. */
|
||||
public static DataStoreFactory getDataStoreFactory() {
|
||||
return dataStoreFactory;
|
||||
}
|
||||
|
||||
/** Creates a test event. */
|
||||
public static Event createTestEvent(Calendar client, String summary) throws IOException {
|
||||
Date oneHourFromNow = Utils.getRelativeDate(java.util.Calendar.HOUR, 1);
|
||||
Date twoHoursFromNow = Utils.getRelativeDate(java.util.Calendar.HOUR, 2);
|
||||
DateTime start = new DateTime(oneHourFromNow, TimeZone.getTimeZone("UTC"));
|
||||
DateTime end = new DateTime(twoHoursFromNow, TimeZone.getTimeZone("UTC"));
|
||||
|
||||
Event event = new Event().setSummary(summary)
|
||||
.setReminders(new Reminders().setUseDefault(false))
|
||||
.setStart(new EventDateTime().setDateTime(start))
|
||||
.setEnd(new EventDateTime().setDateTime(end));
|
||||
return client.events().insert("primary", event).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new {@link java.util.Date} relative to the current date and time.
|
||||
*
|
||||
* @param field the field identifier from {@link java.util.Calendar} to increment
|
||||
* @param amount the amount of the field to increment
|
||||
* @return the new date
|
||||
*/
|
||||
public static Date getRelativeDate(int field, int amount) {
|
||||
Date now = new Date();
|
||||
java.util.Calendar cal = java.util.Calendar.getInstance();
|
||||
cal.setTime(now);
|
||||
cal.add(field, amount);
|
||||
return cal.getTime();
|
||||
}
|
||||
}
|
||||
142
src/main/java/de/jeyp91/openligadb/OpenLigaDBConnector.java
Normal file
142
src/main/java/de/jeyp91/openligadb/OpenLigaDBConnector.java
Normal file
@@ -0,0 +1,142 @@
|
||||
package de.jeyp91.openligadb;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class OpenLigaDBConnector {
|
||||
|
||||
private final String OPENLIGADB_API_URL = "http://www.openligadb.de/api/";
|
||||
|
||||
public OpenLigaDBConnector() {}
|
||||
|
||||
public OpenLigaDBMatch getMatchDataOfSingleMatch(int id) {
|
||||
String url = OPENLIGADB_API_URL + "getmatchdata/" + id;
|
||||
JSONObject matchAsJson = getDataAsJSONObject(url);
|
||||
return new OpenLigaDBMatch(matchAsJson);
|
||||
}
|
||||
|
||||
public ArrayList<OpenLigaDBMatch> getMatchDataOfMatchday(int season, String league, int matchday) {
|
||||
|
||||
String url = OPENLIGADB_API_URL + "getmatchdata/" + league + "/" + (season - 1) + "/" + matchday;
|
||||
|
||||
JSONArray matches = getDataAsJSONArray(url);
|
||||
ArrayList<OpenLigaDBMatch> matchesList = new ArrayList<>();
|
||||
|
||||
for(Object match: matches) {
|
||||
matchesList.add(new OpenLigaDBMatch((JSONObject) match));
|
||||
}
|
||||
|
||||
return matchesList;
|
||||
}
|
||||
|
||||
public ArrayList<OpenLigaDBMatch> getMatchDataOfCurrentMatchday(String league) {
|
||||
|
||||
String url = OPENLIGADB_API_URL + "getmatchdata/" + league;
|
||||
|
||||
JSONArray matches = getDataAsJSONArray(url);
|
||||
ArrayList<OpenLigaDBMatch> matchesList = new ArrayList<>();
|
||||
|
||||
for(Object match: matches) {
|
||||
matchesList.add(new OpenLigaDBMatch((JSONObject) match));
|
||||
}
|
||||
|
||||
return matchesList;
|
||||
}
|
||||
|
||||
public OpenLigaDBMatch getMatchDataByMatchId(int id) {
|
||||
String url = OPENLIGADB_API_URL + "getmatchdata/" + id;
|
||||
JSONObject match = getDataAsJSONObject(url);
|
||||
return new OpenLigaDBMatch(match);
|
||||
}
|
||||
|
||||
private JSONArray getDataAsJSONArray(String requestUrl) {
|
||||
|
||||
String rawData = getRawData(requestUrl);
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONArray data = null;
|
||||
try {
|
||||
data = (JSONArray) parser.parse(rawData);
|
||||
} catch (ParseException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private JSONObject getDataAsJSONObject(String requestUrl) {
|
||||
|
||||
String rawData = getRawData(requestUrl);
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject data = null;
|
||||
try {
|
||||
data = (JSONObject) parser.parse(rawData);
|
||||
} catch (ParseException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private String getRawData(String requestUrl) {
|
||||
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
HttpGet request = new HttpGet(requestUrl);
|
||||
|
||||
// add request header
|
||||
request.addHeader("Content-Type", "application/json");
|
||||
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
response = client.execute(request);
|
||||
} catch (ClientProtocolException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
rd = new BufferedReader(
|
||||
new InputStreamReader(response.getEntity().getContent())
|
||||
);
|
||||
} catch (IOException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line = "";
|
||||
while (true) {
|
||||
try {
|
||||
line = rd.readLine();
|
||||
} catch (IOException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Stop reading if last line was found.
|
||||
if (line == null) break;
|
||||
|
||||
result.append(line);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
88
src/main/java/de/jeyp91/openligadb/OpenLigaDBMatch.java
Normal file
88
src/main/java/de/jeyp91/openligadb/OpenLigaDBMatch.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package de.jeyp91.openligadb;
|
||||
|
||||
import de.jeyp91.BaseMatch;
|
||||
import de.jeyp91.tippliga.TLWMatch;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import java.util.regex.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class OpenLigaDBMatch extends BaseMatch {
|
||||
|
||||
private final int RESULT_TYPE_ENDRESULT = 2;
|
||||
|
||||
private Integer season = null;
|
||||
private int matchId;
|
||||
private int leagueId;
|
||||
private boolean matchIsFinished;
|
||||
|
||||
public OpenLigaDBMatch(JSONObject json) {
|
||||
this.matchId = Integer.parseInt(json.get("MatchID").toString());
|
||||
this.season = getSeasonFromLeageName(json.get("LeagueName").toString());
|
||||
this.leagueId = Integer.parseInt(json.get("LeagueId").toString());
|
||||
this.teamIdHome = Integer.parseInt(((JSONObject) json.get("Team1")).get("TeamId").toString());
|
||||
this.teamIdGuest = Integer.parseInt(((JSONObject) json.get("Team2")).get("TeamId").toString());
|
||||
for(int i = 0; i < ((JSONArray) json.get("MatchResults")).size(); i++) {
|
||||
if(Integer.parseInt((((JSONObject) ((JSONArray) json.get("MatchResults")).get(i)).get("ResultTypeID")).toString()) == RESULT_TYPE_ENDRESULT) {
|
||||
this.goalsHome = Integer.parseInt(((JSONObject) ((JSONArray) json.get("MatchResults")).get(i)).get("PointsTeam1").toString());
|
||||
this.goalsGuest = Integer.parseInt(((JSONObject) ((JSONArray) json.get("MatchResults")).get(i)).get("PointsTeam2").toString());
|
||||
}
|
||||
}
|
||||
this.matchday = Integer.parseInt(((JSONObject) json.get("Group")).get("GroupOrderID").toString());
|
||||
this.matchIsFinished = (Boolean) json.get("MatchIsFinished");
|
||||
this.matchDatetime = (String) json.get("MatchDateTime");
|
||||
}
|
||||
|
||||
private int getSeasonFromLeageName(String leagueName) {
|
||||
Pattern p = Pattern.compile("\\d*/\\d*");
|
||||
Matcher m = p.matcher(leagueName);
|
||||
m.find();
|
||||
String seasonString = m.group();
|
||||
p = Pattern.compile("\\d+");
|
||||
m = p.matcher(seasonString);
|
||||
Integer season = null;
|
||||
while(m.find()) {
|
||||
season = Integer.parseInt(m.group());
|
||||
}
|
||||
return season < 100 ? season + 2000 : season;
|
||||
}
|
||||
|
||||
public boolean isSameMatch(TLWMatch compareMatch) {
|
||||
if(this.getSeason()!= compareMatch.getSeason()) {
|
||||
return false;
|
||||
}
|
||||
if(this.getMatchday() != compareMatch.getMatchday()) {
|
||||
return false;
|
||||
}
|
||||
if(this.getTeamIdHome() != compareMatch.getTeamIdHome()) {
|
||||
return false;
|
||||
}
|
||||
if(this.getTeamIdGuest() != compareMatch.getTeamIdGuest()) {
|
||||
return false;
|
||||
}
|
||||
String thisDateTime = this.getMatchDateTime().replace("T", " ");
|
||||
String tempDateTime = compareMatch.getMatchDateTime().replace("T", " ");
|
||||
if(!tempDateTime.equals(thisDateTime)) {
|
||||
return false;
|
||||
}
|
||||
if(this.goalsHome != compareMatch.getGoalsHome() ||
|
||||
this.goalsGuest != compareMatch.getGoalsGuest()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Integer getSeason() {
|
||||
return this.season;
|
||||
}
|
||||
|
||||
public Integer getMatchId() {
|
||||
return this.matchId;
|
||||
}
|
||||
|
||||
public boolean getMatchIsFinished() {
|
||||
return this.matchIsFinished;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class TLWFootballMatchdaysCreator {
|
||||
|
||||
int season;
|
||||
int league;
|
||||
ArrayList<TLWMatch> matches;
|
||||
int matchesPerMatchday;
|
||||
JSONObject configObject;
|
||||
|
||||
public TLWFootballMatchdaysCreator (int season, int league, String configPath){
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
|
||||
TLWFootballMatchesCreator matchesCreator = new TLWFootballMatchesCreator(2021, 1, configPath);
|
||||
this.matches = matchesCreator.getMatches();
|
||||
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
URL url = Resources.getResource(season + "\\" + configPath);
|
||||
String jsonConfig = null;
|
||||
try {
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
this.configObject = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Read JSON file
|
||||
this.matchesPerMatchday = ((Long) this.configObject.get("matchesPerMatchday")).intValue();
|
||||
}
|
||||
|
||||
public ArrayList<TLWMatchday> getMatchdays() {
|
||||
ArrayList<TLWMatchday> matchdays = new ArrayList<>();
|
||||
|
||||
int matchdayCounter = 1;
|
||||
while(getMatchesForMatchday(matches, matchdayCounter).size() > 0) {
|
||||
ArrayList<TLWMatch> matchesOfMatchday = getMatchesForMatchday(matches, matchdayCounter);
|
||||
String deliveryDate1 = null;
|
||||
String deliveryDate2 = null;
|
||||
Date firstMatchDate = null;
|
||||
for(TLWMatch match : matchesOfMatchday) {
|
||||
if(deliveryDate1 == null) {
|
||||
deliveryDate1 = match.getMatchDateTime();
|
||||
}
|
||||
Date matchdate = null;
|
||||
try {
|
||||
matchdate = new SimpleDateFormat("yyyy-MM-dd").parse(match.getMatchDateTime().substring(0, 10));
|
||||
} catch (java.text.ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(firstMatchDate == null) {
|
||||
firstMatchDate = matchdate;
|
||||
}
|
||||
if(deliveryDate2 == null && getDaysDifference(firstMatchDate, matchdate) >= 1) {
|
||||
deliveryDate2 = match.getMatchDateTime();
|
||||
}
|
||||
}
|
||||
int numberOfMatches = 0;
|
||||
if(this.matchesPerMatchday == 0){
|
||||
numberOfMatches = matchesOfMatchday.size();
|
||||
}
|
||||
String matchdayName = getMatchdayNameFromConfig(matchdayCounter);
|
||||
TLWMatchday matchday = new TLWMatchday(this.season, this.league, matchdayCounter, 0, deliveryDate1, deliveryDate2, "", matchdayName, numberOfMatches);
|
||||
matchdays.add(matchday);
|
||||
matchdayCounter++;
|
||||
}
|
||||
return matchdays;
|
||||
}
|
||||
|
||||
public String getMatchdaysSQL() {
|
||||
String matchdaySql = "";
|
||||
for (TLWMatchday matchday : getMatchdays()) {
|
||||
matchdaySql += "REPLACE INTO phpbb_footb_matchdays VALUES('";
|
||||
matchdaySql += matchday.getSeason().toString();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getLeague().toString();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getMatchday().toString();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getStatus().toString();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getDeliveryDate();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getDeliveryDate2();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getDeliveryDate3();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getMatchdayName();
|
||||
matchdaySql += "', '";
|
||||
matchdaySql += matchday.getMatches().toString();
|
||||
matchdaySql += "');\n";
|
||||
}
|
||||
return matchdaySql;
|
||||
}
|
||||
|
||||
private int getDaysDifference(Date date1, Date date2) {
|
||||
long startTime = date1.getTime();
|
||||
long endTime = date2.getTime();
|
||||
long diffTime = endTime - startTime;
|
||||
long diffDays = diffTime / (1000 * 60 * 60 * 24);
|
||||
return (int) diffDays;
|
||||
}
|
||||
|
||||
private ArrayList<TLWMatch> getMatchesForMatchday(ArrayList<TLWMatch> matches, int matchday) {
|
||||
ArrayList<TLWMatch> matchesOfMatchday = new ArrayList<>();
|
||||
for(TLWMatch match : matches) {
|
||||
if(match.getMatchday() == matchday) {
|
||||
matchesOfMatchday.add(match);
|
||||
}
|
||||
}
|
||||
return matchesOfMatchday;
|
||||
}
|
||||
|
||||
private String getMatchdayNameFromConfig(int matchday) {
|
||||
String matchdayName = "";
|
||||
JSONArray matchdaysConfig = (JSONArray) this.configObject.get("matchdayConfig");
|
||||
for (Object matchdayConfig : matchdaysConfig) {
|
||||
if(((JSONObject) matchdayConfig).get("TLWMatchday").toString().equals(String.valueOf(matchday))
|
||||
&& ((JSONObject) matchdayConfig).containsKey("matchdayName")) {
|
||||
matchdayName = ((JSONObject) matchdayConfig).get("matchdayName").toString();
|
||||
}
|
||||
}
|
||||
return matchdayName;
|
||||
}
|
||||
}
|
||||
191
src/main/java/de/jeyp91/tippliga/TLWFootballMatchesCreator.java
Normal file
191
src/main/java/de/jeyp91/tippliga/TLWFootballMatchesCreator.java
Normal file
@@ -0,0 +1,191 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import de.jeyp91.apifootball.APIFootballConnector;
|
||||
import de.jeyp91.apifootball.APIFootballMatch;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class TLWFootballMatchesCreator {
|
||||
|
||||
int season;
|
||||
int league;
|
||||
int numberOfMatchdays;
|
||||
int matchesPerMatchday;
|
||||
int ko;
|
||||
int nextMatchNo = 1;
|
||||
JSONArray matchdayConfig;
|
||||
|
||||
APIFootballConnector conn;
|
||||
|
||||
ArrayList<TLWMatch> TLWMatches;
|
||||
|
||||
public TLWFootballMatchesCreator(int season, int league, String configFileName) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
conn = new APIFootballConnector(season - 1);
|
||||
|
||||
URL url = Resources.getResource(season + "\\" + configFileName);
|
||||
String jsonConfig = null;
|
||||
|
||||
this.TLWMatches = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||
//Read JSON file
|
||||
JSONObject config = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
this.numberOfMatchdays = ((Long) config.get("numberOfMatchdays")).intValue();
|
||||
this.matchdayConfig = (JSONArray) config.get("matchdayConfig");
|
||||
this.ko = ((Long) config.get("ko")).intValue();
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.publicateMatchObjects();
|
||||
}
|
||||
|
||||
private void publicateMatchObjects() {
|
||||
|
||||
for(int i = 0; i < this.matchdayConfig.size(); i++) {
|
||||
int TLWMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("TLWMatchday")).intValue();
|
||||
JSONArray matchesConfig = (JSONArray)((JSONObject) this.matchdayConfig.get(i)).get("matchesConfig");
|
||||
ArrayList<APIFootballMatch> APIFootballMatches = getMatchesForMatchday(matchesConfig);
|
||||
|
||||
int tempNumberOfMatchesBackup = this.matchesPerMatchday;
|
||||
if(((JSONObject) this.matchdayConfig.get(i)).containsKey("numberOfMatches")) {
|
||||
this.matchesPerMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("numberOfMatches")).intValue();
|
||||
}
|
||||
|
||||
int matchdayMatchCounter = 0;
|
||||
|
||||
// Use first matchtime because API Football always returns matches sorted by date
|
||||
Date firstDate = null;
|
||||
|
||||
for(APIFootballMatch match : APIFootballMatches) {
|
||||
int matchNo = this.nextMatchNo;
|
||||
this.nextMatchNo++;
|
||||
int status = 0;
|
||||
Date matchDateTime = null;
|
||||
try {
|
||||
matchDateTime = new SimpleDateFormat("yyyy-MM-dd").parse(match.getMatchDateTime().substring(0, 10));
|
||||
} catch (java.text.ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(firstDate != null && getDaysDifference(firstDate, matchDateTime) >= 1) {
|
||||
status = -1;
|
||||
}
|
||||
this.TLWMatches.add(new TLWMatch(match, this.season, this.league, TLWMatchday, matchNo, status, this.ko));
|
||||
matchdayMatchCounter++;
|
||||
if(firstDate == null) {
|
||||
firstDate = matchDateTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Add empty missing matches
|
||||
for(int j = matchdayMatchCounter; j < this.matchesPerMatchday; j++) {
|
||||
String matchDatetime = "";
|
||||
if(((JSONObject) matchesConfig.get(0)).get("type").toString().equals("ToBeDefined")) {
|
||||
matchDatetime = ((JSONObject) matchesConfig.get(0)).get("placeholderDatetime").toString();
|
||||
}
|
||||
else if(APIFootballMatches.size() > 0) {
|
||||
matchDatetime = this.TLWMatches.get(this.TLWMatches.size() - 1).getMatchDateTime();
|
||||
}
|
||||
int matchNo = this.nextMatchNo;
|
||||
this.nextMatchNo++;
|
||||
this.TLWMatches.add(new TLWMatch(this.season, this.league, TLWMatchday, matchNo, matchDatetime, 0, this.ko));
|
||||
}
|
||||
|
||||
if(((JSONObject) this.matchdayConfig.get(i)).containsKey("numberOfMatches")) {
|
||||
this.matchesPerMatchday = tempNumberOfMatchesBackup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<APIFootballMatch> getMatchesForMatchday(JSONArray config) {
|
||||
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
||||
for (Object singleConfigObject : config) {
|
||||
JSONObject singleConfig = (JSONObject) singleConfigObject;
|
||||
String type = (String) singleConfig.get("type");
|
||||
switch (type) {
|
||||
case "AllMatchesOfMatchday":
|
||||
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
|
||||
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
|
||||
apiFootballMatches.addAll(conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday));
|
||||
break;
|
||||
case "SingleMatch":
|
||||
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
|
||||
int matchId = ((Long) singleConfig.get("matchId")).intValue();
|
||||
apiFootballMatches.add(conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return apiFootballMatches;
|
||||
}
|
||||
|
||||
private int getDaysDifference(Date date1, Date date2) {
|
||||
long startTime = date1.getTime();
|
||||
long endTime = date2.getTime();
|
||||
long diffTime = endTime - startTime;
|
||||
long diffDays = diffTime / (1000 * 60 * 60 * 24);
|
||||
return (int) diffDays;
|
||||
}
|
||||
|
||||
public ArrayList<TLWMatch> getMatches() {
|
||||
return this.TLWMatches;
|
||||
}
|
||||
|
||||
public String getSQLInsertString() {
|
||||
String sql = "";
|
||||
|
||||
ArrayList<TLWMatch> tlwMatches = getMatches();
|
||||
|
||||
// Add matches from config
|
||||
for(TLWMatch match : tlwMatches) {
|
||||
String teamIdHome = match.getTeamIdHome() != null ? match.getTeamIdHome().toString() : "''";
|
||||
String teamIdGuest = match.getTeamIdGuest() != null ? match.getTeamIdGuest().toString() : "''";
|
||||
|
||||
String matchSql = "REPLACE INTO phpbb_footb_matches VALUES(";
|
||||
matchSql += match.getSeason().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getLeague().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getMatchNo().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += teamIdHome;
|
||||
matchSql += ", ";
|
||||
matchSql += teamIdGuest;
|
||||
// No goals while creating league
|
||||
matchSql += ", '', '', ";
|
||||
matchSql += match.getMatchday().toString();
|
||||
// status 0 while creating
|
||||
matchSql += ", ";
|
||||
matchSql += match.getStatus().toString();
|
||||
matchSql += ", '";
|
||||
matchSql += match.getMatchDateTime();
|
||||
// group_id, formula_home, formula_guest
|
||||
matchSql += "', '', '', '', '";
|
||||
// ko_match,
|
||||
matchSql += match.getKoMatch();
|
||||
// goals_overtime_home, goals_overtime_guest
|
||||
matchSql += "', '', '', ";
|
||||
// show_table
|
||||
matchSql += "0";
|
||||
// trend, odd_1, odd_x, odd_2, rating
|
||||
matchSql += ", '', '0.00', '0.00', '0.00', '0.00');\n";
|
||||
sql += matchSql;
|
||||
}
|
||||
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
79
src/main/java/de/jeyp91/tippliga/TLWLeague.java
Normal file
79
src/main/java/de/jeyp91/tippliga/TLWLeague.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
public class TLWLeague {
|
||||
public static String getLeagueName(int id) {
|
||||
String leagueName = "";
|
||||
switch (id) {
|
||||
case 1:
|
||||
leagueName = "1. Tippliga Würzburg";
|
||||
break;
|
||||
case 2:
|
||||
leagueName = "2. Tippliga Würzburg";
|
||||
break;
|
||||
case 46:
|
||||
leagueName = "Elfmeter";
|
||||
break;
|
||||
case 47:
|
||||
leagueName = "Relegation";
|
||||
break;
|
||||
case 48:
|
||||
leagueName = "WTL-Pokal";
|
||||
break;
|
||||
case 49:
|
||||
leagueName = "Liga-Cup";
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return leagueName;
|
||||
}
|
||||
|
||||
public static String getLeagueNameShort(int id) {
|
||||
String leagueName = "";
|
||||
switch (id) {
|
||||
case 1:
|
||||
leagueName = "1. TLW";
|
||||
break;
|
||||
case 2:
|
||||
leagueName = "2. TLW";
|
||||
break;
|
||||
case 46:
|
||||
leagueName = "ELF";
|
||||
break;
|
||||
case 47:
|
||||
leagueName = "REL";
|
||||
break;
|
||||
case 48:
|
||||
leagueName = "WTL";
|
||||
break;
|
||||
case 49:
|
||||
leagueName = "LC";
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return leagueName;
|
||||
}
|
||||
|
||||
public static String getLeagueNameCalendar(int id) {
|
||||
String leagueName = "";
|
||||
switch (id) {
|
||||
case 1:
|
||||
case 2:
|
||||
leagueName = "TLW";
|
||||
break;
|
||||
case 46:
|
||||
leagueName = "ELF";
|
||||
break;
|
||||
case 47:
|
||||
leagueName = "REL";
|
||||
break;
|
||||
case 48:
|
||||
leagueName = "WTL";
|
||||
break;
|
||||
case 49:
|
||||
leagueName = "LC";
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return leagueName;
|
||||
}
|
||||
}
|
||||
225
src/main/java/de/jeyp91/tippliga/TLWMatch.java
Normal file
225
src/main/java/de/jeyp91/tippliga/TLWMatch.java
Normal file
@@ -0,0 +1,225 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import de.jeyp91.BaseMatch;
|
||||
import de.jeyp91.TeamIDMatcher;
|
||||
import de.jeyp91.apifootball.APIFootballMatch;
|
||||
import de.jeyp91.openligadb.OpenLigaDBMatch;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TLWMatch extends BaseMatch {
|
||||
|
||||
public final Integer STATUS_NOTSTARTED = 0;
|
||||
public final Integer STATUS_STARTED = 1;
|
||||
public final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
|
||||
public final Integer STATUS_FINISHED = 3;
|
||||
|
||||
private Integer season = null;
|
||||
private Integer league = null;
|
||||
private Integer matchNo = null;
|
||||
private String groupId = null;
|
||||
private String formulaHome = null;
|
||||
private String formulaGuest = null;
|
||||
private Integer status = null;
|
||||
private Integer koMatch = 0;
|
||||
private Integer goalsOvertimeHome = null;
|
||||
private Integer goalsOvertimeGuest = null;
|
||||
private Integer showTable = null;
|
||||
private String trend = null;
|
||||
private Float odd1 = null;
|
||||
private Float oddX = null;
|
||||
private Float odd2 = null;
|
||||
private Float rating = null;
|
||||
|
||||
public TLWMatch(ResultSet rset) {
|
||||
|
||||
final int SEASON = 1;
|
||||
final int LEAGUE = 2;
|
||||
final int MATCH_NO = 3;
|
||||
final int TEAM_ID_HOME = 4;
|
||||
final int TEAM_ID_GUEST = 5;
|
||||
final int GOALS_HOME = 6;
|
||||
final int GOALS_GUEST = 7;
|
||||
final int MATCHDAY = 8;
|
||||
final int STATUS = 9;
|
||||
final int MATCH_DATETIME = 10;
|
||||
final int GROUP_ID = 11;
|
||||
final int FORMULA_HOME = 12;
|
||||
final int FORMULA_GUEST = 13;
|
||||
final int KO_MATCH = 14;
|
||||
final int GOALS_OVERTIME_HOME = 15;
|
||||
final int GOALS_OVERTIME_GUEST = 16;
|
||||
final int SHOW_TABLE = 17;
|
||||
final int TREND = 18;
|
||||
final int ODD1 = 19;
|
||||
final int ODDX = 20;
|
||||
final int ODD2 = 21;
|
||||
final int RATING = 22;
|
||||
|
||||
try {
|
||||
this.season = Integer.parseInt(rset.getString(SEASON));
|
||||
this.league = Integer.parseInt(rset.getString(LEAGUE));
|
||||
this.matchNo = Integer.parseInt(rset.getString(MATCH_NO));
|
||||
this.teamIdHome = Integer.parseInt(rset.getString(TEAM_ID_HOME));
|
||||
this.teamIdGuest = Integer.parseInt(rset.getString(TEAM_ID_GUEST));
|
||||
this.goalsHome = rset.getString(GOALS_HOME).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_HOME));
|
||||
this.goalsGuest = rset.getString(GOALS_GUEST).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_GUEST));
|
||||
this.matchday = Integer.parseInt(rset.getString(MATCHDAY));
|
||||
this.status = Integer.parseInt(rset.getString(STATUS));
|
||||
this.matchDatetime = rset.getString(MATCH_DATETIME);
|
||||
this.groupId = rset.getString(GROUP_ID);
|
||||
this.formulaHome = rset.getString(FORMULA_HOME);
|
||||
this.formulaGuest = rset.getString(FORMULA_GUEST);
|
||||
this.koMatch = Integer.parseInt(rset.getString(KO_MATCH));
|
||||
this.goalsOvertimeHome = rset.getString(GOALS_OVERTIME_HOME).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_OVERTIME_HOME));
|
||||
this.goalsOvertimeGuest = rset.getString(GOALS_OVERTIME_GUEST).isEmpty()?null:Integer.parseInt(rset.getString(GOALS_OVERTIME_GUEST));
|
||||
this.showTable = Integer.parseInt(rset.getString(SHOW_TABLE));
|
||||
this.trend = rset.getString(TREND);
|
||||
this.odd1 = Float.parseFloat(rset.getString(ODD1));
|
||||
this.oddX = Float.parseFloat(rset.getString(ODDX));
|
||||
this.odd2 = Float.parseFloat(rset.getString(ODD2));
|
||||
this.rating = Float.parseFloat(rset.getString(RATING));
|
||||
} catch (SQLException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public TLWMatch(OpenLigaDBMatch oldbmatch, int season, int league, int matchday, int matchNo) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchday = matchday;
|
||||
this.matchNo = matchNo;
|
||||
this.teamIdHome = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(oldbmatch.getTeamIdHome());
|
||||
this.teamIdGuest = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(oldbmatch.getTeamIdGuest());
|
||||
this.goalsHome = oldbmatch.getGoalsHome();
|
||||
this.goalsGuest = oldbmatch.getGoalsGuest();
|
||||
this.matchDatetime = oldbmatch.getMatchDateTime().replace("T", " ");
|
||||
this.groupId = "";
|
||||
this.formulaHome = "";
|
||||
this.formulaGuest = "";
|
||||
this.status = 0;
|
||||
}
|
||||
|
||||
public TLWMatch(APIFootballMatch APIFootballMatch, int season, int league, int matchday, int matchNo, int status, int koMatch) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchday = matchday;
|
||||
this.matchNo = matchNo;
|
||||
this.teamIdHome = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(APIFootballMatch.getTeamIdHome());
|
||||
this.teamIdGuest = TeamIDMatcher.getTippligaIdFromOpenLigaDbId(APIFootballMatch.getTeamIdGuest());
|
||||
this.goalsHome = APIFootballMatch.getGoalsHome();
|
||||
this.goalsGuest = APIFootballMatch.getGoalsGuest();
|
||||
this.matchDatetime = APIFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19);
|
||||
this.groupId = "";
|
||||
this.formulaHome = "";
|
||||
this.formulaGuest = "";
|
||||
this.status = status;
|
||||
this.koMatch = koMatch;
|
||||
}
|
||||
|
||||
public TLWMatch(int season, int league, int matchday, int matchNo, String matchDatetime, int status, int koMatch) {
|
||||
this.season = season;
|
||||
this.matchday = matchday;
|
||||
this.league = league;
|
||||
this.matchNo = matchNo;
|
||||
this.formulaHome = "D";
|
||||
this.formulaGuest = "D";
|
||||
this.status = status;
|
||||
this.koMatch = koMatch;
|
||||
this.matchDatetime = matchDatetime;
|
||||
}
|
||||
|
||||
public TLWMatch(int season, int league, int matchday, int matchNo, int teamIdHome, int teamIdGuest, String matchDatetime) {
|
||||
this.season = season;
|
||||
this.matchday = matchday;
|
||||
this.league = league;
|
||||
this.matchNo = matchNo;
|
||||
this.teamIdHome = teamIdHome;
|
||||
this.teamIdGuest = teamIdGuest;
|
||||
this.matchDatetime = matchDatetime;
|
||||
this.status = 0;
|
||||
}
|
||||
|
||||
public Integer getSeason() {
|
||||
return this.season;
|
||||
}
|
||||
|
||||
public Integer getLeague() {
|
||||
return this.league;
|
||||
}
|
||||
|
||||
public Integer getMatchNo() {
|
||||
return this.matchNo;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public Integer getKoMatch() {
|
||||
return this.koMatch;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
public Integer isSameMatch(OpenLigaDBMatch compareMatch) {
|
||||
if(this.getSeason() != compareMatch.getSeason()) {
|
||||
return COMPARISON_DIFFERENT;
|
||||
}
|
||||
if(this.getMatchday() != compareMatch.getMatchday()) {
|
||||
return COMPARISON_DIFFERENT;
|
||||
}
|
||||
if(this.getTeamIdHome() != compareMatch.getTeamIdHome()) {
|
||||
return COMPARISON_DIFFERENT;
|
||||
}
|
||||
if(this.getTeamIdGuest() != compareMatch.getTeamIdGuest()) {
|
||||
return COMPARISON_DIFFERENT;
|
||||
}
|
||||
String thisDateTime = this.getMatchDateTime().replace("T", " ");
|
||||
String tempDateTime = compareMatch.getMatchDateTime().replace("T", " ");
|
||||
if(!tempDateTime.equals(thisDateTime)) {
|
||||
return COMPARISON_DIFFERENT_DATETIME;
|
||||
}
|
||||
if(this.goalsHome != compareMatch.getGoalsHome() ||
|
||||
this.goalsGuest != compareMatch.getGoalsGuest()) {
|
||||
return COMPARISON_DIFFERENT_RESULT;
|
||||
}
|
||||
return COMPARISON_IDENTICAL;
|
||||
}
|
||||
|
||||
public String getSQLQueryReplace() {
|
||||
|
||||
String query = "REPLACE INTO phpbb_footb_matches VALUES (" +
|
||||
this.season + ", " +
|
||||
this.league + ", " +
|
||||
this.matchNo + ", " +
|
||||
nullToSqlEmptyString(this.teamIdHome) + ", " +
|
||||
nullToSqlEmptyString(this.teamIdGuest) + ", " +
|
||||
nullToSqlEmptyString(this.goalsHome) + ", " +
|
||||
nullToSqlEmptyString(this.goalsGuest) + ", " +
|
||||
this.matchday + ", " +
|
||||
this.status + ", " +
|
||||
"'" + this.matchDatetime + "', " +
|
||||
"'" + this.groupId + "', " +
|
||||
"'" + this.formulaHome + "', " +
|
||||
"'" + this.formulaGuest + "', " +
|
||||
nullToSqlEmptyString(this.koMatch) + ", " +
|
||||
nullToSqlEmptyString(this.goalsOvertimeHome) + ", " +
|
||||
nullToSqlEmptyString(this.goalsOvertimeGuest) + ", " +
|
||||
nullToSqlEmptyString(this.showTable) + ", " +
|
||||
"'0.00','0.00','0.00','0.00');";
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
private String nullToSqlEmptyString(Integer number) {
|
||||
return number != null ? number.toString() : "''";
|
||||
}
|
||||
}
|
||||
99
src/main/java/de/jeyp91/tippliga/TLWMatchday.java
Normal file
99
src/main/java/de/jeyp91/tippliga/TLWMatchday.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TLWMatchday {
|
||||
|
||||
final Integer STATUS_NOTSTARTED = 0;
|
||||
final Integer STATUS_STARTED = 1;
|
||||
final Integer STATUS_PROVISIONAL_RESULT_AVAILABLE = 2;
|
||||
final Integer STATUS_FINISHED = 3;
|
||||
|
||||
private Integer season = null;
|
||||
private Integer league = null;
|
||||
private Integer matchday = null;
|
||||
private Integer status = null;
|
||||
private String deliveryDate = null;
|
||||
private String deliveryDate2 = null;
|
||||
private String deliveryDate3 = null;
|
||||
private String matchdayName = null;
|
||||
private Integer matches = null;
|
||||
|
||||
public TLWMatchday(ResultSet rset) {
|
||||
|
||||
final int SEASON = 1;
|
||||
final int LEAGUE = 2;
|
||||
final int MATCHDAY = 3;
|
||||
final int STATUS = 4;
|
||||
final int DELIVERY_DATE = 5;
|
||||
final int DELIVERY_DATE_2 = 6;
|
||||
final int DELIVERY_DATE_3 = 7;
|
||||
final int MATCHDAY_NAME = 8;
|
||||
final int MATCHES = 9;
|
||||
|
||||
try {
|
||||
this.season = Integer.parseInt(rset.getString(SEASON));
|
||||
this.league = Integer.parseInt(rset.getString(LEAGUE));
|
||||
this.matchday = Integer.parseInt(rset.getString(MATCHDAY));
|
||||
this.status = Integer.parseInt(rset.getString(STATUS));
|
||||
this.deliveryDate = rset.getString(DELIVERY_DATE);
|
||||
this.deliveryDate2 = rset.getString(DELIVERY_DATE_2);
|
||||
this.deliveryDate3 = rset.getString(DELIVERY_DATE_3);
|
||||
this.matchdayName = rset.getString(MATCHDAY_NAME);
|
||||
this.matches = Integer.parseInt(rset.getString(MATCHES));
|
||||
} catch (SQLException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public TLWMatchday(int season, int league, int matchday, int status, String deliveryDate1, String deliveryDate2, String deliveryDate3, String matchdayName, int numberOfMatches) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchday = matchday;
|
||||
this.status = status;
|
||||
this.deliveryDate = deliveryDate1;
|
||||
this.deliveryDate2 = deliveryDate2;
|
||||
this.deliveryDate3 = deliveryDate3;
|
||||
this.matchdayName = matchdayName;
|
||||
this.matches = numberOfMatches;
|
||||
}
|
||||
|
||||
public Integer getSeason() {
|
||||
return this.season;
|
||||
}
|
||||
|
||||
public Integer getLeague() {
|
||||
return this.league;
|
||||
}
|
||||
|
||||
public Integer getMatchday() {
|
||||
return this.matchday;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public String getDeliveryDate() {
|
||||
return this.deliveryDate == null ? "" : this.deliveryDate;
|
||||
}
|
||||
|
||||
public String getDeliveryDate2() {
|
||||
return this.deliveryDate2 == null ? "" : this.deliveryDate2;
|
||||
}
|
||||
|
||||
public String getDeliveryDate3() {
|
||||
return this.deliveryDate3 == null ? "" : this.deliveryDate3;
|
||||
}
|
||||
|
||||
public String getMatchdayName() {
|
||||
return this.matchdayName;
|
||||
}
|
||||
|
||||
public Integer getMatches() {
|
||||
return this.matches;
|
||||
}
|
||||
}
|
||||
71
src/main/java/de/jeyp91/tippliga/TLWTeam.java
Normal file
71
src/main/java/de/jeyp91/tippliga/TLWTeam.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TLWTeam {
|
||||
|
||||
private int season;
|
||||
private int league;
|
||||
private int teamId;
|
||||
private String teamName;
|
||||
private String teamNameShort;
|
||||
private String teamSymbol;
|
||||
private String groupId;
|
||||
private int matchday;
|
||||
|
||||
public TLWTeam(ResultSet rset) throws SQLException {
|
||||
final int SEASON = 1;
|
||||
final int LEAGUE = 2;
|
||||
final int TEAM_ID = 3;
|
||||
final int TEAM_NAME = 4;
|
||||
final int TEAM_NAME_SHORT = 5;
|
||||
final int TEAM_SYMBOL = 6;
|
||||
final int GROUP_ID = 7;
|
||||
final int MATCHDAY = 8;
|
||||
|
||||
this.season = Integer.parseInt(rset.getString(SEASON));
|
||||
this.league = Integer.parseInt(rset.getString(LEAGUE));
|
||||
this.teamId = Integer.parseInt(rset.getString(TEAM_ID));
|
||||
this.teamName = rset.getString(TEAM_NAME);
|
||||
this.teamNameShort = rset.getString(TEAM_NAME_SHORT);
|
||||
this.teamSymbol = rset.getString(TEAM_SYMBOL);
|
||||
this.groupId = rset.getString(GROUP_ID);
|
||||
this.matchday = Integer.parseInt(rset.getString(MATCHDAY));
|
||||
}
|
||||
|
||||
public int getSeason() {
|
||||
return this.season;
|
||||
}
|
||||
|
||||
public int getLeague() {
|
||||
return this.league;
|
||||
}
|
||||
|
||||
public int getTeamId() {
|
||||
return this.teamId;
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return this.teamName;
|
||||
}
|
||||
|
||||
public String getTeamNameShort() {
|
||||
return this.teamNameShort;
|
||||
}
|
||||
|
||||
public String getTeamSymbol() {
|
||||
return this.teamSymbol;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
public int getMatchday() {
|
||||
return this.matchday;
|
||||
}
|
||||
}
|
||||
62
src/main/java/de/jeyp91/tippliga/TLWTeamsPokalCreator.java
Normal file
62
src/main/java/de/jeyp91/tippliga/TLWTeamsPokalCreator.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TLWTeamsPokalCreator {
|
||||
int season;
|
||||
int league;
|
||||
ArrayList<TLWMatch> matches;
|
||||
TippligaSQLConnector connector = new TippligaSQLConnector();
|
||||
|
||||
public TLWTeamsPokalCreator(int season, int league, ArrayList<TLWMatch> matches) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matches = matches;
|
||||
}
|
||||
|
||||
public Set<Integer> getTeamIds() {
|
||||
Set<Integer> teamIds = new LinkedHashSet<>();
|
||||
for(TLWMatch match : matches) {
|
||||
if(match.getTeamIdHome() != null) {
|
||||
teamIds.add(match.getTeamIdHome());
|
||||
}
|
||||
if(match.getTeamIdGuest() != null) {
|
||||
teamIds.add(match.getTeamIdGuest());
|
||||
}
|
||||
}
|
||||
return teamIds;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
Set<Integer> teamIds = getTeamIds();
|
||||
String sql = "";
|
||||
for (Integer id : teamIds) {
|
||||
ArrayList<TLWTeam> teams = connector.getTeamsById(String.valueOf(id));
|
||||
String teamName = teams.get(0).getTeamName();
|
||||
String teamNameShort = teams.get(0).getTeamNameShort();
|
||||
String teamSymbol = teams.get(0).getTeamSymbol();
|
||||
String groupId = "";
|
||||
int matchday = 0;
|
||||
sql += "REPLACE INTO phpbb_footb_teams VALUES ('";
|
||||
sql += this.season;
|
||||
sql += "', '";
|
||||
sql += this.league;
|
||||
sql += "', '";
|
||||
sql += id;
|
||||
sql += "', '";
|
||||
sql += teamName;
|
||||
sql += "', '";
|
||||
sql += teamNameShort;
|
||||
sql += "', '";
|
||||
sql += teamSymbol;
|
||||
sql += "', '";
|
||||
sql += groupId;
|
||||
sql += "', '";
|
||||
sql += matchday;
|
||||
sql += "');\n";
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
143
src/main/java/de/jeyp91/tippliga/TLWTipperMatchesCreator.java
Normal file
143
src/main/java/de/jeyp91/tippliga/TLWTipperMatchesCreator.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TLWTipperMatchesCreator {
|
||||
|
||||
int season;
|
||||
int league;
|
||||
|
||||
ArrayList<TLWMatch> TLWMatches;
|
||||
JSONArray matchPairingConfig;
|
||||
JSONObject tipperList;
|
||||
JSONArray tipperTeamConfig;
|
||||
ArrayList<TLWMatchday> matchdays;
|
||||
|
||||
public TLWTipperMatchesCreator(int season, int league, String configFileName, ArrayList<TLWMatchday> matchdays) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchdays = matchdays;
|
||||
|
||||
URL matchPairConfigUrl = Resources.getResource("Tipper_Match_Pair_Config.json");
|
||||
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
|
||||
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
||||
|
||||
this.TLWMatches = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
|
||||
String matchPairingConfigString = Resources.toString(matchPairConfigUrl, StandardCharsets.UTF_8);
|
||||
this.matchPairingConfig = (JSONArray) jsonParser.parse(matchPairingConfigString);
|
||||
|
||||
String tipperListString = Resources.toString(tipperListUrl, StandardCharsets.UTF_8);
|
||||
this.tipperList = (JSONObject) jsonParser.parse(tipperListString);
|
||||
|
||||
String tipperTeamConfigString = Resources.toString(tipperTeamConfigUrl, StandardCharsets.UTF_8);
|
||||
this.tipperTeamConfig = (JSONArray) jsonParser.parse(tipperTeamConfigString);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.publicateMatchObjects();
|
||||
}
|
||||
|
||||
private void publicateMatchObjects() {
|
||||
|
||||
for(Object matchdayConfig : this.matchPairingConfig) {
|
||||
|
||||
int matchday = ((Long) ((JSONObject) matchdayConfig).get("matchday")).intValue();
|
||||
JSONArray matchesConfig = (JSONArray)((JSONObject) matchdayConfig).get("matches");
|
||||
|
||||
for(int i = 0; i < matchesConfig.size(); i++) {
|
||||
int homeTipperNumber = ((Long) ((JSONObject) matchesConfig.get(i)).get("home")).intValue();
|
||||
int guestTipperNumber = ((Long) ((JSONObject) matchesConfig.get(i)).get("guest")).intValue();
|
||||
|
||||
String homeName = this.tipperList.get(String.valueOf(homeTipperNumber)).toString();
|
||||
String guestName = this.tipperList.get(String.valueOf(guestTipperNumber)).toString();
|
||||
|
||||
int teamIdHome = getTeamIdFromTipperName(homeName);
|
||||
int teamIdGuest = getTeamIdFromTipperName(guestName);
|
||||
|
||||
int matchNo = (matchday - 1) * matchesConfig.size() + i + 1;
|
||||
|
||||
String matchDatetime = getDeliveryDateForMatchday(matchday);
|
||||
|
||||
TLWMatch tlwMatch = new TLWMatch(this.season, this.league, matchday, matchNo, teamIdHome, teamIdGuest, matchDatetime);
|
||||
this.TLWMatches.add(tlwMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getTeamIdFromTipperName(String name) {
|
||||
int teamId = 0;
|
||||
for(Object config : tipperTeamConfig) {
|
||||
if (((JSONObject) config).get("team_name").toString().equals(name)) {
|
||||
teamId = ((Long) (((JSONObject) config).get("team_id"))).intValue();
|
||||
}
|
||||
}
|
||||
if(teamId == 0) {
|
||||
System.out.println("Did not find Tipper ID for " + name);
|
||||
}
|
||||
return teamId;
|
||||
}
|
||||
|
||||
public ArrayList<TLWMatch> getMatches() {
|
||||
return this.TLWMatches;
|
||||
}
|
||||
|
||||
public String getSQLInsertString() {
|
||||
String sql = "";
|
||||
|
||||
ArrayList<TLWMatch> tlwMatches = getMatches();
|
||||
|
||||
// Add matches from config
|
||||
for(TLWMatch match : tlwMatches) {
|
||||
String matchSql = "REPLACE INTO phpbb_footb_matches VALUES(";
|
||||
matchSql += match.getSeason().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getLeague().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getMatchNo().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getTeamIdHome().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getTeamIdGuest().toString();
|
||||
// No goals while creating league
|
||||
matchSql += ", '', '', ";
|
||||
matchSql += match.getMatchday().toString();
|
||||
// status 0 while creating
|
||||
matchSql += ", 0, '";
|
||||
matchSql += match.getMatchDateTime();
|
||||
// group_id, formula_home, formula_guest, ko_match, goals_overtime_home, goals_overtime_guest
|
||||
matchSql += "', '', '', '', 0, '', '', ";
|
||||
// show_table
|
||||
matchSql += "0";
|
||||
// trend, odd_1, odd_x, odd_2, rating
|
||||
matchSql += ", '', '0.00', '0.00', '0.00', '0.00');\n";
|
||||
sql += matchSql;
|
||||
}
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
private String getDeliveryDateForMatchday(int matchday) {
|
||||
String deliveryDate = "";
|
||||
for (TLWMatchday matchdayObject : this.matchdays) {
|
||||
if(matchdayObject.getMatchday() == matchday) {
|
||||
deliveryDate = matchdayObject.getDeliveryDate();
|
||||
}
|
||||
}
|
||||
return deliveryDate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TLWTipperPokalMatchesCreator {
|
||||
|
||||
int season;
|
||||
int league;
|
||||
|
||||
ArrayList<TLWMatch> TLWMatches;
|
||||
JSONObject tipperList;
|
||||
JSONArray tipperTeamConfig;
|
||||
ArrayList<TLWMatchday> matchdays;
|
||||
|
||||
public TLWTipperPokalMatchesCreator(int season, int league, String configFileName, ArrayList<TLWMatchday> matchdays) {
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
this.matchdays = matchdays;
|
||||
|
||||
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
|
||||
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
||||
|
||||
this.TLWMatches = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
|
||||
String tipperListString = Resources.toString(tipperListUrl, StandardCharsets.UTF_8);
|
||||
this.tipperList = (JSONObject) jsonParser.parse(tipperListString);
|
||||
|
||||
String tipperTeamConfigString = Resources.toString(tipperTeamConfigUrl, StandardCharsets.UTF_8);
|
||||
this.tipperTeamConfig = (JSONArray) jsonParser.parse(tipperTeamConfigString);
|
||||
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.publicateMatchObjects();
|
||||
}
|
||||
|
||||
private void publicateMatchObjects() {
|
||||
|
||||
int matchday = 1;
|
||||
|
||||
for(int i = 1; i < 13; i++) {
|
||||
|
||||
String homeName = this.tipperList.get(String.valueOf(2 * i - 1)).toString();
|
||||
String guestName = this.tipperList.get(String.valueOf(2 * i)).toString();
|
||||
|
||||
int teamIdHome = getTeamIdFromTipperName(homeName);
|
||||
int teamIdGuest = getTeamIdFromTipperName(guestName);
|
||||
|
||||
int matchNo = i;
|
||||
|
||||
String matchDatetime = getDeliveryDateForMatchday(matchday);
|
||||
|
||||
TLWMatch tlwMatch = new TLWMatch(this.season, this.league, matchday, matchNo, teamIdHome, teamIdGuest, matchDatetime);
|
||||
this.TLWMatches.add(tlwMatch);
|
||||
}
|
||||
}
|
||||
|
||||
private int getTeamIdFromTipperName(String name) {
|
||||
int teamId = 0;
|
||||
for(Object config : tipperTeamConfig) {
|
||||
if (((JSONObject) config).get("team_name").toString().equals(name)) {
|
||||
teamId = ((Long) (((JSONObject) config).get("team_id"))).intValue();
|
||||
}
|
||||
}
|
||||
if(teamId == 0) {
|
||||
System.out.println("Did not find Tipper ID for " + name);
|
||||
}
|
||||
return teamId;
|
||||
}
|
||||
|
||||
public ArrayList<TLWMatch> getMatches() {
|
||||
return this.TLWMatches;
|
||||
}
|
||||
|
||||
public String getSQLInsertString() {
|
||||
String sql = "";
|
||||
|
||||
ArrayList<TLWMatch> tlwMatches = getMatches();
|
||||
|
||||
// Add matches from config
|
||||
for(TLWMatch match : tlwMatches) {
|
||||
String matchSql = "REPLACE INTO phpbb_footb_matches VALUES(";
|
||||
matchSql += match.getSeason().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getLeague().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getMatchNo().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getTeamIdHome().toString();
|
||||
matchSql += ", ";
|
||||
matchSql += match.getTeamIdGuest().toString();
|
||||
// No goals while creating league
|
||||
matchSql += ", '', '', ";
|
||||
matchSql += match.getMatchday().toString();
|
||||
// status 0 while creating
|
||||
matchSql += ", 0, '";
|
||||
matchSql += match.getMatchDateTime();
|
||||
// group_id, formula_home, formula_guest, ko_match, goals_overtime_home, goals_overtime_guest
|
||||
matchSql += "', '', '', '', 0, '', '', ";
|
||||
// show_table
|
||||
matchSql += "0";
|
||||
// trend, odd_1, odd_x, odd_2, rating
|
||||
matchSql += ", '', '0.00', '0.00', '0.00', '0.00');\n";
|
||||
sql += matchSql;
|
||||
}
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
private String getDeliveryDateForMatchday(int matchday) {
|
||||
String deliveryDate = "";
|
||||
for (TLWMatchday matchdayObject : this.matchdays) {
|
||||
if(matchdayObject.getMatchday() == matchday) {
|
||||
deliveryDate = matchdayObject.getDeliveryDate();
|
||||
}
|
||||
}
|
||||
return deliveryDate;
|
||||
}
|
||||
}
|
||||
99
src/main/java/de/jeyp91/tippliga/TippligaSQLConnector.java
Normal file
99
src/main/java/de/jeyp91/tippliga/TippligaSQLConnector.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import de.jeyp91.tippliga.TLWMatch;
|
||||
import de.jeyp91.tippliga.TLWTeam;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class TippligaSQLConnector {
|
||||
|
||||
Connection con;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
System.err.println("Unable to load MySQL Driver");
|
||||
}
|
||||
}
|
||||
|
||||
public TippligaSQLConnector() {
|
||||
String jdbcUrl = "jdbc:mysql://localhost/d0144ddb?user=root&password=&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
|
||||
try {
|
||||
con = DriverManager.getConnection(jdbcUrl);
|
||||
} catch (SQLException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<TLWTeam> getTeamsBySeasonAndLeague(String season, String league) {
|
||||
String queryString = "SELECT * FROM `phpbb_footb_teams` WHERE `season` = " + season + " AND `league` = " + league + ";";
|
||||
Statement stmt = null;
|
||||
ResultSet rset = null;
|
||||
ArrayList<TLWTeam> teams = new ArrayList<TLWTeam>();
|
||||
try {
|
||||
stmt = con.createStatement();
|
||||
rset = stmt.executeQuery(queryString);
|
||||
while ( rset.next()) {
|
||||
teams.add(new TLWTeam(rset));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
teams.sort((t1, t2) -> t1.getTeamId() - t2.getTeamId());
|
||||
|
||||
return teams;
|
||||
}
|
||||
|
||||
public ArrayList<TLWTeam> getTeamsById(String id) {
|
||||
String queryString = "SELECT * FROM `phpbb_footb_teams` WHERE `team_id` = " + id + ";";
|
||||
Statement stmt = null;
|
||||
ResultSet rset = null;
|
||||
ArrayList<TLWTeam> teams = new ArrayList<TLWTeam>();
|
||||
try {
|
||||
stmt = con.createStatement();
|
||||
rset = stmt.executeQuery(queryString);
|
||||
while ( rset.next()) {
|
||||
teams.add(new TLWTeam(rset));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
/* TODO */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return teams;
|
||||
}
|
||||
|
||||
public ArrayList<TLWMatch> getMatchesBySeasonAndLeague(String season, String league) {
|
||||
String queryString = "SELECT * FROM `phpbb_footb_matches` WHERE `season` = " + season + " AND `league` = " + league + ";";
|
||||
Statement stmt = null;
|
||||
ResultSet rset = null;
|
||||
ArrayList<TLWMatch> matches = new ArrayList<TLWMatch>();
|
||||
try {
|
||||
stmt = con.createStatement();
|
||||
rset = stmt.executeQuery(queryString);
|
||||
while (rset.next()) {
|
||||
matches.add(new TLWMatch(rset));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
public void updateMatchDateTime(String season, String league, String matchNo, String datetime) {
|
||||
String queryString = "UPDATE `phpbb_footb_matches` "
|
||||
+ "SET match_datetime = " + datetime
|
||||
+ " WHERE `season` = " + season
|
||||
+ " AND `league` = " + league
|
||||
+ " AND match_no = " + matchNo + ";";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user