Created
December 19, 2019 17:32
-
-
Save jonasgroendahl/1c6bb9a92173800d30d1665fce123e15 to your computer and use it in GitHub Desktop.
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
const cheerio = require("cheerio"); | |
const fetch = require("node-fetch"); | |
const getOngoingAndUpcomingMatches = async () => { | |
const res = await fetch("https://www.joindota.com/en/start"); | |
const html = await res.text(); | |
const $ = cheerio.load(html); | |
const results = $(".widget-ticker-container") | |
.first() | |
.find("tbody tr") | |
.toArray() | |
.filter(e => { | |
const findSpan = $(e).find( | |
".col-2 .table-cell-container .table-cell-item" | |
); | |
const previousResult = findSpan | |
.attr("class") | |
.includes("antispoiler-score"); | |
if (!previousResult) { | |
return e; | |
} | |
}) | |
.map(e => { | |
let result = $(e) | |
.find(".col-2.col-text-center span") | |
.text(); | |
if (!result) { | |
result = $(e) | |
.find(".col-2.col-text-center span.itime") | |
.attr("data-time"); | |
result = formatDistance(new Date(result * 1000), new Date()); | |
} | |
return { | |
team1: $(e) | |
.find(".col-3:first-child span:nth-child(2)") | |
.text(), | |
team2: $(e) | |
.find(".col-3.col-text-right span:first-child") | |
.text(), | |
results: result | |
}; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment