Port the football module to football-data.org API v4 - #2177
Open
MexKeon wants to merge 3 commits into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's happening
The football module targets football-data.org API v2, which no longer returns
matches for the current season. Comparing the same window on both versions:
v2 still answers, and still returns last season's data, it isn't being fed the current season's data. The module shows
an empty widget.
This PR ports the module to v4.
Changes
API v4 migration
/v2to/v4.score.fullTimeis keyedhome/awayin v4, where v2 usedhomeTeam/awayTeam. This is because the old struct tagsunmarshal against v4 without error and silently produce zero values, so every
finished match would render
0 - 0with no error message.ScoreByTimenow holds*intand a helperrenders a missing value as
-rather than a0.dateTois exclusive in v4. The request now asks for one day beyondmatchesToso the configured window stays inclusive, as documented.TOTAL,HOMEandAWAYstandings tables for a leaguecompetition. The old code took
Standings[0], which was only the overalltable by accident of ordering; there's now an explicit lookup for the
TOTALtable, falling back to the first block if no type is set.
Match status handling (separate commit)
TIMEDfixtures are now shown. The switch previously matched onlySCHEDULEDandFINISHED, so a fixture whose kick-off time had beenconfirmed was dropped without trace. In the sample above, that's all six.
IN_PLAYandPAUSEDmatches render with their running score, andAWARDEDis treated as finished.
POSTPONED,SUSPENDEDandCANCELLEDare surfaced with their statusrather than vanishing.
Drive-by fix (separate commit)
footballRequestused the request object before checking the error fromhttp.NewRequest, which would panic rather than return the error.Testing
go test ./modules/football/passes. Existing tests were updated to v4 payloadshapes, and new ones cover the
TIMEDcase, a live match, a non-played status,the inclusive date range, and
TOTALtable selection.Documentation
Per CONTRIBUTING.md, the
matchesTochange affects a documented configurationparameter: the same YAML value now produces a different window. I'm happy to
open a companion PR against wtfdocs once the direction here is agreed.
Open questions
caused. If you'd rather keep this PR to the port alone, I'll
drop that commit and raise it separately.
LeagueFixtuerstypo, theleagueIDmap(
EL2: 444looks stale, and v4 accepts competition codes directly, thoughwtf's codes don't match football-data's), multi-group standings for
competitions like the Champions League, and rendering penalty-shootout
results via
score.duration.