forked from MagicMirrorOrg/MagicMirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MagicMirrorOrg#6 from fewieden/feature/voice-control
Feature/voice control
- Loading branch information
Showing
10 changed files
with
349 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* Magic Mirror | ||
* Module: MMM-NFL | ||
* | ||
* By fewieden https://github.com/fewieden/MMM-NFL | ||
* MIT Licensed. | ||
*/ | ||
const jsdom = require("jsdom"); | ||
|
||
module.exports = { | ||
|
||
URL: "http://www.espn.com/nfl/statistics", | ||
CACHE_TIME: 2*60*1000, //2 minutes | ||
|
||
statistics: { | ||
timestamp: null, | ||
data: {} | ||
}, | ||
|
||
getStats: function(type, callback){ | ||
var time = Date.now(); | ||
if(!this.statistics.timestamp || this.statistics.timestamp < time - this.CACHE_TIME || !this.statistics.data.hasOwnProperty(type.toUpperCase())){ | ||
jsdom.env({ | ||
url: this.URL, | ||
done: (err, window) => { | ||
if(err){ | ||
callback(err, null); | ||
} else { | ||
var statistics = {}; | ||
var statisticsWrapper = window.document.querySelector("#my-players-table"); | ||
if(statisticsWrapper){ | ||
var teams = [statisticsWrapper.children[0], statisticsWrapper.children[1]]; | ||
for(var i = 0; i < teams.length; i++){ | ||
var types = teams[i].children; | ||
for(var n = 0; n < types.length; n++){ | ||
var rows = types[n].querySelector("tbody").children; | ||
if(rows){ | ||
statistics[rows[0].children[0].textContent] = {unit: rows[0].children[1].textContent, players: []}; | ||
for(var x = 1; x < rows.length - 1; x++){ | ||
var text = rows[x].children[rows[x].children.length -2].textContent; | ||
statistics[rows[0].children[0].textContent].players.push({ | ||
position: text[0], | ||
player: text.slice(3, text.lastIndexOf(",")), | ||
team: text.slice(text.lastIndexOf(",") + 2) === "WSH" ? "WAS" : text.slice(text.lastIndexOf(",") + 2), | ||
value: rows[x].children[rows[x].children.length - 1].textContent | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
window.close(); | ||
|
||
this.statistics = { | ||
timestamp: time, | ||
data: statistics | ||
}; | ||
|
||
if(this.statistics.data.hasOwnProperty(type.toUpperCase())){ | ||
callback(null, {type: type, data: this.statistics.data[type.toUpperCase()]}); | ||
} else { | ||
callback("Statistics for " + type + " not found!", null); | ||
} | ||
} else { | ||
callback("Source changed site layout!", null); | ||
} | ||
} | ||
} | ||
}); | ||
} else { | ||
callback(null, {type: type, data: this.statistics.data[type.toUpperCase()]}); | ||
} | ||
} | ||
}; |
Oops, something went wrong.