Skip to content

Commit

Permalink
Filter pictorials and dance practice teasers from /news (#1835)
Browse files Browse the repository at this point in the history
* Filter pictorials from /news

* Exclude dance practice teasers
  • Loading branch information
taahamahdi authored Feb 1, 2024
1 parent 4a7afc5 commit 2caea85
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/helpers/reddit_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,41 @@ export class RedditClient {
query: generateFilteredQuery(),
sort: "top",
time: newsRangeToRedditInterval(interval),
count: 30,
});

const popularPosts = matchingPosts
return matchingPosts
.filter((x) => x.score > 100)
.slice(0, 25);

return popularPosts.map((x) => {
const flairGroup = x.link_flair_css_class as string;
let flair = (x.link_flair_text as string).toLowerCase();
if (flair.startsWith("[") && flair.endsWith("]")) {
flair = flair.slice(1, flair.length - 1);
}

if (flair === "album discussion") {
flair = "album";
}

return {
title: x.title,
link: `https://reddit.com${x.permalink}`,
date: new Date(x.created_utc * 1000),
flair: `${flairGroup}:${flair}`,
x: Date.now() - new Date(x.created_utc * 1000).getTime(),
};
});
.filter((x) => !x.title.toLowerCase().includes("pictorial"))
.slice(0, 25)
.map((x) => {
const flairGroup = x.link_flair_css_class as string;
let flair = (x.link_flair_text as string).toLowerCase();
if (flair.startsWith("[") && flair.endsWith("]")) {
flair = flair.slice(1, flair.length - 1);
}

if (flair === "album discussion") {
flair = "album";
}

return {
title: x.title,
link: `https://reddit.com${x.permalink}`,
date: new Date(x.created_utc * 1000),
flair: `${flairGroup}:${flair}`,
x:
Date.now() -
new Date(x.created_utc * 1000).getTime(),
};
})
.filter(
(x) =>
!(
x.flair.startsWith("teaser") &&
x.title.toLowerCase().includes("dance practice")
),
);
} catch (e) {
logger.warn(
`Failed to fetch getTopPosts(). interval = ${newsRangeToRedditInterval(
Expand Down

0 comments on commit 2caea85

Please sign in to comment.