Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: V3 with cup support #42

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
extract football-data in multiple files, map api data to custom forma…
…t, 3 letter team codes, adjusted templates to display data
  • Loading branch information
fewieden committed Apr 12, 2021
commit 29be1a24cee018fd4451bbec2d4c387576bf5d62
2 changes: 1 addition & 1 deletion MMM-soccer.js
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ Module.register('MMM-soccer', {
let focusTeamIndex = -1;

for (let i = 0; i < this.standing.length; i += 1) {
if (this.standing[i].team.name === this.config.focus_on[this.config.show]) {
if (this.standing[i].team === this.config.focus_on[this.config.show]) {
focusTeamIndex = i;
break;
}
16 changes: 16 additions & 0 deletions provider/football-data/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const BASE_URL = 'https://api.football-data.org/v2';

const PROVIDER_NAME = 'football-data';

const COMPETITIONS = {
BL1: 'BL1',
PL: 'PL',
SA: 'SA',
FL1: 'FL1',
PD: 'PD',
PPL: 'PPL',
DED: 'DED',
BSA: 'BSA'
};

module.exports = {BASE_URL, PROVIDER_NAME, COMPETITIONS};
3 changes: 3 additions & 0 deletions provider/football-data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const {init, fetchStandings} = require('./provider');

module.exports = {init, fetchStandings};
34 changes: 18 additions & 16 deletions provider/football-data.js → provider/football-data/provider.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
const _ = require('lodash');
const fetch = require('node-fetch');

const {registerProvider} = require('./provider');
const {SoccerError, COMPETITION_NOT_SUPPORTED, FETCHING_STANDINGS, API_LIMIT_REACHED, API_KEY_REQUIRED} = require('./utils');

const BASE_URL = 'http://api.football-data.org/v2';
const PROVIDER_NAME = 'football-data';
const COMPETITIONS = {
BL1: 'BL1',
PL: 'PL',
SA: 'SA',
FL1: 'FL1',
PD: 'PD',
PPL: 'PPL',
DED: 'DED',
BSA: 'BSA'
};
const {registerProvider} = require('../provider');
const {SoccerError, COMPETITION_NOT_SUPPORTED, FETCHING_STANDINGS, API_LIMIT_REACHED, API_KEY_REQUIRED} = require('../utils');

const {getTeamCode} = require('./teams');
const {BASE_URL, PROVIDER_NAME, COMPETITIONS} = require('./constants');

let apiKey;

@@ -37,6 +27,16 @@ function getRequestOptions() {
return {headers: {'X-Auth-Token': apiKey}};
}

function mapStandingEntry(entry = {}) {
return {
position: entry.position,
logo: _.get(entry, ['team', 'crestUrl']),
team: getTeamCode(entry.team),
points: entry.points,
goalDifference: entry.goalDifference
};
}

async function fetchStandings(competition) {
const competitionId = getCompetitionId(competition);

@@ -50,11 +50,13 @@ async function fetchStandings(competition) {

const parsedResponse = await response.json();

const standings = _.get(parsedResponse, ['standings', 0, 'table']);

return {
code: competition,
competition: _.get(parsedResponse, 'competition'),
season: _.get(parsedResponse, 'season'),
standings: _.get(parsedResponse, ['standings', 0, 'table'])
standings: _.map(standings, mapStandingEntry)
};
}

179 changes: 179 additions & 0 deletions provider/football-data/teams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
const _ = require('lodash');

const mapping = {
// BRAZIL
1783: 'FLA',
6684: 'INL',
1766: 'AMN',
1776: 'SAO',
1765: 'FLU',
1767: 'GRE',
1769: 'PAL',
6685: 'STS',
1768: 'APR',
4286: 'RBB',
1837: 'CEA',
1779: 'CTH',
3988: 'AGO',
1777: 'BAH',
1778: 'REC',
3984: 'FOR',
1780: 'VAG',
4250: 'GOI',
4241: 'CTB',
1770: 'BOT',

// ENGLAND
65: 'MCI',
66: 'MUN',
338: 'LEI',
563: 'WHU',
61: 'CHE',
64: 'LIV',
73: 'TOT',
62: 'EVE',
57: 'ARS',
341: 'LEE',
58: 'AVA',
76: 'WLV',
354: 'CRY',
340: 'SOU',
328: 'BUR',
397: 'BRH',
67: 'NEW',
63: 'FUL',
74: 'WBA',
356: 'SHU',

// FRANCE
521: 'LILO',
524: 'PSG',
548: 'AMO',
523: 'LYO',
546: 'LEN',
516: 'OLM',
529: 'REN',
518: 'MPL',
522: 'NCE',
545: 'MTZ',
532: 'ANG',
547: 'REI',
527: 'STE',
576: 'STR',
526: 'BOR',
512: 'B29',
525: 'LOR',
556: 'NIM',
543: 'NAN',
528: 'DIJ',

// GERMANY
5: 'BAY',
721: 'RBL',
11: 'WOB',
19: 'SGE',
4: 'DOR',
3: 'B04',
28: 'UNB',
18: 'BMG',
10: 'STU',
17: 'SCF',
16: 'AUG',
2: 'TSG',
12: 'SVW',
15: 'MAI',
9: 'BCS',
38: 'BIE',
1: 'CGN',
6: 'S04',

// ITALY
108: 'INT',
98: 'MIL',
109: 'JUV',
102: 'ATT',
113: 'NAP',
110: 'LAZ',
100: 'ROM',
450: 'HEL',
471: 'SAS',
584: 'SAM',
103: 'BGN',
115: 'UDI',
107: 'GEN',
488: 'SPZ',
99: 'FIO',
1106: 'BEN',
586: 'TOR',
104: 'CAG',
112: 'PRM',
472: 'CRO',

// NETHERLANDS
678: 'AJA',
674: 'PSV',
682: 'AZA',
679: 'VIT',
675: 'FEY',
677: 'GRO',
676: 'UTR',
671: 'HEA',
666: 'TWE',
673: 'HEE',
6806: 'SPR',
1920: 'FST',
684: 'PEC',
683: 'WAA',
672: 'WIL',
668: 'VVV',
1914: 'EMM',
680: 'ADO',

// PORTUGAL
498: 'SLI',
503: 'POR',
1903: 'SLB',
5613: 'SBR',
507: 'PAC',
5543: 'VDG',
5530: 'SCL',
583: 'MOE',
5601: 'PRT',
5533: 'GVI',
1049: 'TND',
496: 'RIO',
5531: 'FAM',
5568: 'BLN',
810: 'BOA',
5575: 'MTI',
5602: 'FAR',
5529: 'CDN',

// SPAIN
78: 'ATM',
86: 'MAD',
81: 'FCB',
559: 'SEV',
92: 'SOC',
90: 'BET',
94: 'VIL',
83: 'GCF',
88: 'LVT',
558: 'CLV',
77: 'ATB',
264: 'CCF',
95: 'VAL',
79: 'OSA',
82: 'GET',
299: 'HUE',
250: 'REV',
285: 'ELC',
263: 'ALV',
278: 'EIB',
};

function getTeamCode(team = {}) {
return _.get(mapping, team.id, team.name);
}

module.exports = {getTeamCode};
10 changes: 8 additions & 2 deletions templates/MMM-soccer.njk
Original file line number Diff line number Diff line change
@@ -22,9 +22,15 @@
<tr class="centered-row {% if index === boundaries.focusTeamIndex %}bright{% endif %}" style="{{ index | fade(boundaries.focusTeamIndex) }}">
<td>{{ standing[index].position }}</td>
{% if config.logos %}
<td><img class="icon {% if not config.colored %}no-color{% endif %}" src="{{ standing[index].team.crestUrl }}"/></td>
<td><img class="icon {% if not config.colored %}no-color{% endif %}" src="{{ standing[index].logo }}"/></td>
{% endif %}
<td class="name">{{ standing[index].team.name }}</td>
<td class="name">
{% if config.shortNames %}
{{ standing[index].team }}
{% else %}
{{ standing[index].team | translate }}
{% endif %}
</td>
<td class="centered">{{ standing[index].points }}</td>
<td class="centered">{{ standing[index].goalDifference }}</td>
</tr>
11 changes: 9 additions & 2 deletions templates/StandingsModal.njk
Original file line number Diff line number Diff line change
@@ -19,9 +19,16 @@
<tr class="centered-row {% if loop.index0 === data.boundaries.focusTeamIndex %}bright{% endif %}">
<td>{{ entry.position }}</td>
{% if data.config.logos %}
<td><img class="icon {% if not data.config.colored %}no-color{% endif %}" src="{{ entry.team.crestUrl }}"/></td>
<td><img class="icon {% if not data.config.colored %}no-color{% endif %}" src="{{ entry.logo }}"/></td>
{% endif %}
<td class="name">{{ entry.team.name }}</td>
<td class="name">
{{ entry.team.name }}
{% if data.config.shortNames %}
{{ entry.team }}
{% else %}
{{ data.fns.translate(entry.team) }}
{% endif %}
</td>
<td class="centered">{{ entry.points }}</td>
<td class="centered">{{ entry.goalDifference }}</td>
</tr>
Loading