<commit_before>package main

import (
	"bytes"
	"fmt"
	"image"
	"net/http"

	"github.com/animenotifier/arn"
	"github.com/parnurzeal/gorequest"
)

// Avatar represents a single image and the name of the format.
type Avatar struct {
	User   *arn.User
	Image  image.Image
	Data   []byte
	Format string
}

// String returns a text representation of the format, width and height.
func (avatar *Avatar) String() string {
	return fmt.Sprint(avatar.Format, " | ", avatar.Image.Bounds().Dx(), "x", avatar.Image.Bounds().Dy())
}

// AvatarFromURL downloads and decodes the image from an URL and creates an Avatar.
func AvatarFromURL(url string, user *arn.User) *Avatar {
	// Download
	response, data, networkErr := gorequest.New().Get(url).EndBytes()

	if networkErr != nil {
		avatarLog.Error("NET", user.Nick, url, networkErr)
		return nil
	}

	if response.StatusCode != http.StatusOK {
		avatarLog.Error("NET", user.Nick, url, response.StatusCode)
		return nil
	}

	// Decode
	img, format, decodeErr := image.Decode(bytes.NewReader(data))

	if decodeErr != nil {
		avatarLog.Error("IMG", user.Nick, url, decodeErr)
		return nil
	}

	return &Avatar{
		User:   user,
		Image:  img,
		Data:   data,
		Format: format,
	}
}
<commit_msg>Added a retry for network requests<commit_after>package main

import (
	"bytes"
	"fmt"
	"image"
	"net/http"
	"time"

	"github.com/animenotifier/arn"
	"github.com/parnurzeal/gorequest"
)

// Avatar represents a single image and the name of the format.
type Avatar struct {
	User   *arn.User
	Image  image.Image
	Data   []byte
	Format string
}

// String returns a text representation of the format, width and height.
func (avatar *Avatar) String() string {
	return fmt.Sprint(avatar.Format, " | ", avatar.Image.Bounds().Dx(), "x", avatar.Image.Bounds().Dy())
}

// AvatarFromURL downloads and decodes the image from an URL and creates an Avatar.
func AvatarFromURL(url string, user *arn.User) *Avatar {
	// Download
	response, data, networkErr := gorequest.New().Get(url).EndBytes()

	// Retry after 5 seconds if service unavailable
	if response.StatusCode == http.StatusServiceUnavailable {
		time.Sleep(5 * time.Second)
		response, data, networkErr = gorequest.New().Get(url).EndBytes()
	}

	// Network errors
	if networkErr != nil {
		avatarLog.Error("NET", user.Nick, url, networkErr)
		return nil
	}

	// Bad status codes
	if response.StatusCode != http.StatusOK {
		avatarLog.Error("NET", user.Nick, url, response.StatusCode)
		return nil
	}

	// Decode
	img, format, decodeErr := image.Decode(bytes.NewReader(data))

	if decodeErr != nil {
		avatarLog.Error("IMG", user.Nick, url, decodeErr)
		return nil
	}

	return &Avatar{
		User:   user,
		Image:  img,
		Data:   data,
		Format: format,
	}
}

{'fraction_non_alphanumeric': 0.1309611151870873, 'fraction_numerical': 0.0007336757153338225, 'mean_word_length': 3.801056338028169, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1320757', 'n_tokens_mistral': 988, 'n_tokens_neox': 942, 'n_words': 263}