Skip to content

Commit

Permalink
fix: make lastMatches / nextMatches more resilient
Browse files Browse the repository at this point in the history
This fixes an issue where lastMatches would be the same as nextMatches
if no last matches table was found.
  • Loading branch information
czosel committed Jan 7, 2023
1 parent cbfbf48 commit ff8a3fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 6 additions & 8 deletions client/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import clientHref from "../../lib/link";

const baseUrl = "http://click-tt.ch/cgi-bin/WebObjects/nuLigaTTCH.woa/wa";

const getClickTTPath = (path) => {
if (path.indexOf("/club/") > -1) {
return path.replace("/club/", "/clubInfoDisplay?club=").slice(0, -1);
const getClickTTPath = (url) => {
if (url.indexOf("/club/") > -1) {
return url.replace("/club/", "/clubInfoDisplay?club=").slice(0, -1);
}
return decodeURIComponent(
path.split("/").filter((s) => s.includes("%2F"))[0]
);
return decodeURIComponent(url.split("/").filter((s) => s.includes("%2F"))[0]);
};

export default class Header extends Component {
Expand Down Expand Up @@ -71,8 +69,8 @@ export default class Header extends Component {
Spielersuche
</Link>
<Match>
{({ path }) => {
const clickTTPath = getClickTTPath(path);
{({ url }) => {
const clickTTPath = getClickTTPath(url);
return (
clickTTPath.length > 10 && (
<a
Expand Down
10 changes: 7 additions & 3 deletions server/lib/scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ function club(id) {
.find("#content")
.set({
lastMatches: osmosis
.find("#content-row2 table.result-set:first tr")
.find(
"//table[@class='result-set'][count(preceding-sibling::*[1][self::h2][contains(.,'Rückschau')]) > 0]//tr"
)
.set({
date: "td:nth-child(2)",
time: "td:nth-child(3)",
Expand All @@ -248,7 +250,9 @@ function club(id) {
result: "td:nth-child(11)",
}),
nextMatches: osmosis
.find("#content-row2 table.result-set:last tr")
.find(
"//table[@class='result-set'][count(preceding-sibling::*[1][self::h2][contains(.,'Vorschau')]) > 0]//tr"
)
.set({
date: "td:nth-child(2)",
time: "td:nth-child(3)",
Expand All @@ -257,7 +261,7 @@ function club(id) {
guest: "td:nth-child(9)",
}),
})
.error(R.pipe(error("club"), rej))
.error(error("scraping error in /club, continuing anyway"))
.data((data) => {
res({
lastMatches: asChunks(
Expand Down

0 comments on commit ff8a3fc

Please sign in to comment.