Use league name from database for calendar
This commit is contained in:
@@ -4,10 +4,9 @@ import com.google.api.client.util.DateTime;
|
||||
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 de.jeyp91.tippligaforum.TippligaSQLConnector;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -16,7 +15,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static de.jeyp91.googlecalendar.GoogleCalendarConnector.getSerivce;
|
||||
@@ -26,6 +25,8 @@ public class TippligaGoogleEventManager {
|
||||
private static List<Event> allEvents = null;
|
||||
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) {
|
||||
if(allEvents == null) {
|
||||
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) {
|
||||
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";
|
||||
String description = getDescription(matchday.getSeason(), matchday.getLeague(), matchday.getMatchday(), deliverDateNumber);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,50 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TLWLeague {
|
||||
public static String getLeagueName(int id) {
|
||||
String leagueName = "";
|
||||
switch (id) {
|
||||
case 1:
|
||||
leagueName = "Tippliga";
|
||||
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;
|
||||
|
||||
private Integer season = null;
|
||||
private Integer league = null;
|
||||
private String leagueName = null;
|
||||
private String leagueNameShort = null;
|
||||
|
||||
public TLWLeague(ResultSet rset) {
|
||||
final int SEASON = 1;
|
||||
final int LEAGUE = 2;
|
||||
final int LEAGUE_NAME = 3;
|
||||
final int LEAGUE_NAME_SHORT = 4;
|
||||
try {
|
||||
this.season = Integer.parseInt(rset.getString(SEASON));
|
||||
this.league = Integer.parseInt(rset.getString(LEAGUE));
|
||||
this.leagueName = rset.getString(LEAGUE_NAME);
|
||||
this.leagueNameShort = rset.getString(LEAGUE_NAME_SHORT);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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 Integer getSeason() {
|
||||
return this.season;
|
||||
}
|
||||
|
||||
public static String getLeagueNameCalendar(int id) {
|
||||
String leagueName = "";
|
||||
switch (id) {
|
||||
case 1:
|
||||
case 2:
|
||||
leagueName = "Tippliga";
|
||||
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;
|
||||
public Integer getLeague() {
|
||||
return this.league;
|
||||
}
|
||||
|
||||
public String getLeagueName() {
|
||||
return this.leagueName;
|
||||
}
|
||||
|
||||
public String getLeagueNameShort() {
|
||||
return this.leagueNameShort;
|
||||
}
|
||||
|
||||
public String getLeagueNameCalendar() {
|
||||
String leagueName = this.leagueName;
|
||||
if (leagueName.equals("1. Tippliga") || leagueName.equals("2. Tippliga")) {
|
||||
leagueName = "Tippliga";
|
||||
}
|
||||
return leagueName;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.jeyp91.tippligaforum;
|
||||
|
||||
import de.jeyp91.StatusHolder;
|
||||
import de.jeyp91.tippliga.TLWLeague;
|
||||
import de.jeyp91.tippliga.TLWMatch;
|
||||
import de.jeyp91.tippliga.TLWMatchday;
|
||||
import de.jeyp91.tippliga.TLWTeam;
|
||||
@@ -140,6 +141,20 @@ public class TippligaSQLConnector {
|
||||
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) {
|
||||
String queryString = """
|
||||
SELECT
|
||||
@@ -252,7 +267,7 @@ public class TippligaSQLConnector {
|
||||
|
||||
public void updatePost(int postId, String postText) {
|
||||
String postChecksum = getChecksum(postText);
|
||||
final long postEditTime = Instant.now().getEpochSecond();;
|
||||
final long postEditTime = Instant.now().getEpochSecond();
|
||||
final String postEditReason = "Update by tool.";
|
||||
int postEditUser = 2;
|
||||
String query = getPostUpdateQuery(postId, postText, postChecksum, postEditTime, postEditReason, postEditUser);
|
||||
|
||||
Reference in New Issue
Block a user