mirror of
https://github.com/davegallant/rfd-fyi.git
synced 2025-08-07 09:02:27 +00:00
Fetch first 400 deals
This commit is contained in:
@@ -101,24 +101,28 @@ func (a *App) refreshDeals() {
|
|||||||
|
|
||||||
func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
|
func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
|
||||||
|
|
||||||
// TODO: Fetch multiple pages
|
var t []Topic
|
||||||
requestURL := fmt.Sprintf("https://forums.redflagdeals.com/api/topics?forum_id=%d&per_page=40&page=%d", id, firstPage)
|
|
||||||
res, err := http.Get(requestURL)
|
for i := firstPage; i < lastPage; i++ {
|
||||||
if err != nil {
|
requestURL := fmt.Sprintf("https://forums.redflagdeals.com/api/topics?forum_id=%d&per_page=40&page=%d", id, i)
|
||||||
log.Warn().Msgf("error fetching deals: %s\n", err)
|
res, err := http.Get(requestURL)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Msgf("error fetching deals: %s\n", err)
|
||||||
|
}
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Msgf("could not read response body: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response TopicsResponse
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(body), &response)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Msgf("could not unmarshal response body: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t = append(t, response.Topics...)
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
return t
|
||||||
if err != nil {
|
|
||||||
log.Warn().Msgf("could not read response body: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var response TopicsResponse
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(body), &response)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Warn().Msgf("could not unmarshal response body: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.Topics
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@@ -31,7 +31,7 @@
|
|||||||
>
|
>
|
||||||
<td scope="col">
|
<td scope="col">
|
||||||
<a
|
<a
|
||||||
href="'https://forums.redflagdeals.com' + topic.web_path"
|
:href="`https://forums.redflagdeals.com${topic.web_path}`"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
v-html="highlightMatches(topic.title)"
|
v-html="highlightMatches(topic.title)"
|
||||||
></a>
|
></a>
|
||||||
|
Reference in New Issue
Block a user