Fix downloading of forums with many pages
This commit is contained in:
@@ -5,27 +5,49 @@
|
||||
package fetcher
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
func downloadAdditionalPages() {
|
||||
for i := range forumPagesLinks {
|
||||
forumPage, _ := strconv.Atoi(i)
|
||||
const (
|
||||
forumPageOffset = 50
|
||||
)
|
||||
|
||||
func downloadAdditionalPages(forumID int) {
|
||||
forumPage := 2
|
||||
|
||||
for {
|
||||
dlog.Info().Int("номер страницы", forumPage).Msg("Скачивается ещё одна страница форума")
|
||||
|
||||
pageFile, err := downloadFile("https://"+c.Config.URL+"/forum/"+forumPagesLinks[i], true)
|
||||
pageURL := fmt.Sprintf(
|
||||
"https://%s/forum/viewforum.php?f=%d&start=%d#pagestart",
|
||||
c.Config.URL, forumID, (forumPage-1)*forumPageOffset,
|
||||
)
|
||||
|
||||
if uberDebug {
|
||||
dlog.Debug().Str("URL страницы", pageURL).Msg("Сформирован URL для скачивания")
|
||||
}
|
||||
|
||||
pageFile, err := downloadFile(pageURL, true)
|
||||
if err != nil {
|
||||
dlog.Fatal().Err(err).Msg("Не удалось загрузить страницу форума")
|
||||
}
|
||||
|
||||
_ = setQuerier(pageFile, "forumPage", forumPage)
|
||||
err = setQuerier(pageFile, "forumPage", forumPage)
|
||||
if err != nil {
|
||||
dlog.Info().Str("причина завершения", err.Error()).
|
||||
Msg("Завершено скачивание страниц форума")
|
||||
// Found empty page, leaving cycle
|
||||
break
|
||||
}
|
||||
|
||||
forumPage++
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user