Skip to content

Instantly share code, notes, and snippets.

@jonasgroendahl
Created December 19, 2019 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasgroendahl/1c6bb9a92173800d30d1665fce123e15 to your computer and use it in GitHub Desktop.
Save jonasgroendahl/1c6bb9a92173800d30d1665fce123e15 to your computer and use it in GitHub Desktop.
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