Use league name from database for calendar

This commit is contained in:
2024-06-12 20:35:36 +02:00
parent 1889be5b14
commit 0d5307cf1a
3 changed files with 69 additions and 69 deletions

View File

@@ -4,10 +4,9 @@ import com.google.api.client.util.DateTime;
import com.google.api.services.calendar.Calendar; import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event; import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.EventDateTime; 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 com.google.api.services.calendar.model.Events;
import de.jeyp91.tippliga.TLWLeague;
import de.jeyp91.tippliga.TLWMatchday; import de.jeyp91.tippliga.TLWMatchday;
import de.jeyp91.tippligaforum.TippligaSQLConnector;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -16,7 +15,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.HashMap;
import java.util.List; import java.util.List;
import static de.jeyp91.googlecalendar.GoogleCalendarConnector.getSerivce; import static de.jeyp91.googlecalendar.GoogleCalendarConnector.getSerivce;
@@ -26,6 +25,8 @@ public class TippligaGoogleEventManager {
private static List<Event> allEvents = null; private static List<Event> allEvents = null;
private static final Logger logger = LogManager.getLogger(TippligaGoogleEventManager.class); private static final Logger logger = LogManager.getLogger(TippligaGoogleEventManager.class);
private static final HashMap<String, String> allLeagueNames = new HashMap<>();
public static List<Event> getAllEvents(Integer season) { public static List<Event> getAllEvents(Integer season) {
if(allEvents == null) { if(allEvents == null) {
allEvents = getAllEventsStartingFromDateTime(new DateTime(season-1 + "-07-01T00:00:00Z")); allEvents = getAllEventsStartingFromDateTime(new DateTime(season-1 + "-07-01T00:00:00Z"));
@@ -144,7 +145,7 @@ public class TippligaGoogleEventManager {
private static Event getEvent(TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) { private static Event getEvent(TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) {
String matchdayName = matchday.getMatchdayName().equals("") ? matchday.getMatchday().toString() + ". Spieltag" : matchday.getMatchdayName(); String matchdayName = matchday.getMatchdayName().equals("") ? matchday.getMatchday().toString() + ". Spieltag" : matchday.getMatchdayName();
String summary = TLWLeague.getLeagueNameCalendar(matchday.getLeague()) + " " + matchdayName + " tippen!"; String summary = getLeagueNameCalendar(matchday.getSeason(), matchday.getLeague()) + " " + matchdayName + " tippen!";
if(deliverDateNumber > 1) summary += " " + deliverDateNumber + ". Chance \uD83D\uDE43"; if(deliverDateNumber > 1) summary += " " + deliverDateNumber + ". Chance \uD83D\uDE43";
String description = getDescription(matchday.getSeason(), matchday.getLeague(), matchday.getMatchday(), deliverDateNumber); String description = getDescription(matchday.getSeason(), matchday.getLeague(), matchday.getMatchday(), deliverDateNumber);
String location = "https://tippliga-wuerzburg.de/app.php/football/bet"; String location = "https://tippliga-wuerzburg.de/app.php/football/bet";
@@ -195,4 +196,13 @@ public class TippligaGoogleEventManager {
} }
}); });
} }
private static String getLeagueNameCalendar(Integer season, Integer league) {
String seasonLeagueId = season.toString() + league.toString();
if(!allLeagueNames.containsKey(seasonLeagueId)) {
allLeagueNames.put(seasonLeagueId, TippligaSQLConnector.getInstance().getLeague(season.toString(), league.toString()).getLeagueNameCalendar());
}
return allLeagueNames.get(seasonLeagueId);
}
} }

View File

@@ -1,75 +1,50 @@
package de.jeyp91.tippliga; package de.jeyp91.tippliga;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TLWLeague { public class TLWLeague {
public static String getLeagueName(int id) {
String leagueName = ""; private Integer season = null;
switch (id) { private Integer league = null;
case 1: private String leagueName = null;
leagueName = "Tippliga"; private String leagueNameShort = null;
break;
case 46: public TLWLeague(ResultSet rset) {
leagueName = "Elfmeter"; final int SEASON = 1;
break; final int LEAGUE = 2;
case 47: final int LEAGUE_NAME = 3;
leagueName = "Relegation"; final int LEAGUE_NAME_SHORT = 4;
break; try {
case 48: this.season = Integer.parseInt(rset.getString(SEASON));
leagueName = "WTL-Pokal"; this.league = Integer.parseInt(rset.getString(LEAGUE));
break; this.leagueName = rset.getString(LEAGUE_NAME);
case 49: this.leagueNameShort = rset.getString(LEAGUE_NAME_SHORT);
leagueName = "Liga-Cup"; } catch (SQLException e) {
break; e.printStackTrace();
default: break;
} }
return leagueName;
} }
public static String getLeagueNameShort(int id) { public Integer getSeason() {
String leagueName = ""; return this.season;
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) { public Integer getLeague() {
String leagueName = ""; return this.league;
switch (id) { }
case 1:
case 2: public String getLeagueName() {
leagueName = "Tippliga"; return this.leagueName;
break; }
case 46:
leagueName = "Elfmeter"; public String getLeagueNameShort() {
break; return this.leagueNameShort;
case 47: }
leagueName = "Relegation";
break; public String getLeagueNameCalendar() {
case 48: String leagueName = this.leagueName;
leagueName = "WTL-Pokal"; if (leagueName.equals("1. Tippliga") || leagueName.equals("2. Tippliga")) {
break; leagueName = "Tippliga";
case 49:
leagueName = "Liga Cup";
break;
default: break;
} }
return leagueName; return leagueName;
} }

View File

@@ -1,6 +1,7 @@
package de.jeyp91.tippligaforum; package de.jeyp91.tippligaforum;
import de.jeyp91.StatusHolder; import de.jeyp91.StatusHolder;
import de.jeyp91.tippliga.TLWLeague;
import de.jeyp91.tippliga.TLWMatch; import de.jeyp91.tippliga.TLWMatch;
import de.jeyp91.tippliga.TLWMatchday; import de.jeyp91.tippliga.TLWMatchday;
import de.jeyp91.tippliga.TLWTeam; import de.jeyp91.tippliga.TLWTeam;
@@ -140,6 +141,20 @@ public class TippligaSQLConnector {
return matchdays; return matchdays;
} }
public TLWLeague getLeague(String season, String league) {
String queryString = "SELECT * FROM `phpbb_footb_leagues` WHERE `season` = " + season + " AND `league` = " + league + ";";
ResultSet rset = executeQuery(queryString);
TLWLeague tlwLeague = null;
try {
while (rset.next()) {
tlwLeague = new TLWLeague(rset);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return tlwLeague;
}
public ArrayList<TLWMatchday> getUpdatedMatchdaysBasedOnMatches(String season, String league) { public ArrayList<TLWMatchday> getUpdatedMatchdaysBasedOnMatches(String season, String league) {
String queryString = """ String queryString = """
SELECT SELECT
@@ -252,7 +267,7 @@ public class TippligaSQLConnector {
public void updatePost(int postId, String postText) { public void updatePost(int postId, String postText) {
String postChecksum = getChecksum(postText); String postChecksum = getChecksum(postText);
final long postEditTime = Instant.now().getEpochSecond();; final long postEditTime = Instant.now().getEpochSecond();
final String postEditReason = "Update by tool."; final String postEditReason = "Update by tool.";
int postEditUser = 2; int postEditUser = 2;
String query = getPostUpdateQuery(postId, postText, postChecksum, postEditTime, postEditReason, postEditUser); String query = getPostUpdateQuery(postId, postText, postChecksum, postEditTime, postEditReason, postEditUser);