A scriptable script to view next SVW match information as iOS lockscreen widget.
Utilizes openligadb.de
api.
Last active
January 13, 2025 16:32
-
-
Save nsmlzl/f73ad4d7d2876aaa4ff459beb8c87476 to your computer and use it in GitHub Desktop.
next_svw_match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const blID = "4741" | |
const svwID = "134" | |
const teamDB = { | |
"Borussia Dortmund": "BVB", | |
"Bayer Leverkusen": "B04", | |
"TSG 1899 Hoffenheim": "TSG", | |
"VfL Wolfsburg": "WOB", | |
"1. FC Heidenheim 1846": "FCH", | |
"1. FC Union Berlin": "FCU", | |
"SC Freiburg": "SCF", | |
"Holstein Kiel": "KSV", | |
"1. FSV Mainz 05": "M05", | |
"VfL Bochum": "BOC", | |
"FC St. Pauli": "STP", | |
"Eintracht Frankfurt": "SGE", | |
"Borussia Mönchengladbach": "BMG", | |
"FC Bayern München": "FCB", | |
"RB Leipzig": "RBL", | |
"Werder Bremen": "SVW", | |
"FC Augsburg": "FCA", | |
"VfB Stuttgart": "VFB" | |
} | |
let reqURL = "https://api.openligadb.de/getnextmatchbyleagueteam/" + blID + "/" + svwID | |
let offline = true | |
let req = new Request(reqURL) | |
let resp = await req.loadJSON() | |
.then((result) => { | |
offline = false | |
return result | |
}) | |
.catch((error) => { | |
offline = true | |
}) | |
const w = new ListWidget() | |
if (offline) { | |
y = w.addText("data un-available (offline)") | |
y.rightAlignText() | |
y.font = Font.mediumRoundedSystemFont(11) | |
} | |
else { | |
console.log(resp) | |
let md = getMatchDate(resp) | |
let homeAwaySym = getHomeAwaySymbol(resp) | |
let oppTeamShrt = getOpposingTeam(resp) | |
let dateStr = getDate(md) | |
let timeStr = getTime(md) | |
y = w.addText(homeAwaySym + " " + oppTeamShrt) | |
y.rightAlignText() | |
y.font = Font.boldMonospacedSystemFont(14) | |
y = w.addText(dateStr) | |
y.rightAlignText() | |
y.font = Font.lightMonospacedSystemFont(12) | |
y = w.addText(timeStr) | |
y.rightAlignText() | |
y.font = Font.lightMonospacedSystemFont(10) | |
} | |
Script.setWidget(w) | |
Script.complete() | |
function getHomeAwaySymbol(resp) { | |
let homeSymbol = "@" | |
if (resp["team1"]["teamId"] == svwID) homeSymbol = "vs" | |
return homeSymbol | |
} | |
function getOpposingTeam(resp) { | |
let oppTeamShrt = "???" | |
let oppTeamName = "" | |
if (resp["team1"]["teamId"] == svwID) oppTeamName = resp["team2"]["teamName"] | |
else oppTeamName = resp["team1"]["teamName"] | |
console.log(oppTeamName) | |
if (oppTeamName in teamDB) { | |
oppTeamShrt = teamDB[oppTeamName] | |
} | |
return oppTeamShrt | |
} | |
function getMatchDate(resp) { | |
let matchDate = new Date(resp["matchDateTime"] + "Z") | |
matchDate.setHours(matchDate.getHours() - 1) | |
// if summer time | |
const startDate = new Date(matchDate.getYear().toString() + "-03-30") | |
const endDate = new Date(matchDate.getYear().toString() + "-10-26") | |
if (matchDate >= startDate && matchDate < endDate) { | |
matchDate.setHours(matchDate.getHours() - 1) | |
} | |
console.log(matchDate) | |
return matchDate | |
} | |
function getDate(md) { | |
let today = new Date() | |
today.setHours(0,0,1,0) | |
console.log(today) | |
let mdc = new Date(md.getTime()) | |
mdc.setHours(0,0,1,0) | |
console.log(mdc) | |
if (mdc.getTime() == today.getTime()) return "TODAY" | |
// within next week | |
tdate = today | |
tdate.setDate(tdate.getDate() + 7) | |
if (mdc <= tdate) { | |
options = { weekday: 'short' } | |
} else { | |
// print normal | |
options = { day: '2-digit', month: '2-digit' } | |
} | |
return md.toLocaleDateString("en-US", options).toLocaleUpperCase() | |
} | |
function getTime(md) { | |
const options = { hour: 'numeric', minute: '2-digit'} | |
return md.toLocaleTimeString("en-US", options).toLocaleLowerCase().replace(/\s+/g, '') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment