Skip sponsored topics

This commit is contained in:
Dave Gallant
2022-12-25 09:28:50 -05:00
parent 195c79c6a6
commit 5d7c061508
2 changed files with 12 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"strings"
"time" "time"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
@@ -104,6 +105,10 @@ func (a *App) updateScores(t []Topic) []Topic {
return t return t
} }
func (a *App) isSponsor(t Topic) bool {
return strings.HasPrefix(t.Title, "[Sponsored]")
}
func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic { func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
var t []Topic var t []Topic
@@ -127,7 +132,12 @@ func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
log.Warn().Msgf("could not unmarshal response body: %s\n %s", err) log.Warn().Msgf("could not unmarshal response body: %s\n %s", err)
} }
t = append(t, response.Topics...) for _, topic := range response.Topics {
if a.isSponsor(topic) {
continue
}
t = append(t, topic)
}
} }
return t return t
} }

View File

@@ -146,7 +146,7 @@ export default {
Deal: "deal", Deal: "deal",
Score: "score", Score: "score",
Views: "total_views", Views: "total_views",
"Last Comment": "last_post_time", "Last Reply": "last_post_time",
}; };
}, },
filteredTopics() { filteredTopics() {