fix: crash on visited page & logging

Update error handling and logging in Furaffinaty client
This commit is contained in:
SoXX 2024-08-09 12:04:37 +02:00
parent 3390a05c70
commit dfca20a3ec

View File

@ -115,7 +115,8 @@ func (c *Client) GetSubmissionIDsForFavorites(username string) ([]string, error)
err := c.RequestContext.Client.Visit(submissionURL)
if err != nil {
return nil, err
log.Println(err)
break
}
log.Printf("Next Submission URL: %s", nextSubmissionURL)
@ -139,6 +140,7 @@ func (c *Client) GetSubmissionIDsForFavorites(username string) ([]string, error)
// GetSubmissions
// Set limit to 0 if you want all submissions
func (c *Client) GetSubmissions(limit int) ([]models.Submission, error) {
submissionLength := 0
if c.submissionIDs == nil {
log.Println("No IDs found, scraping IDs...")
@ -150,13 +152,18 @@ func (c *Client) GetSubmissions(limit int) ([]models.Submission, error) {
if limit == 0 {
limit = len(c.submissionIDs)
submissionLength = len(c.submissionIDs)
} else {
submissionLength = limit
}
for _, id := range c.submissionIDs[:limit] {
for i, id := range c.submissionIDs[:limit] {
log.Printf("Working on submission: %s | Number: %d, from: %d", id, i, submissionLength)
submissionURL := fmt.Sprintf("%s/view/%s", c.RequestContext.Host, id)
var submission models.Submission
submission.ID = id
submission.Url = submissionURL
c.RequestContext.Client.OnHTML("#submissionImg", func(e *colly.HTMLElement) {
submission.Image.DataFullviewSrc = e.Attr("data-fullview-src")