<commit_before>package wms

import (
	"net/http"
	"net/url"
	"strings"

	"github.com/bfontaine/gostruct"
)

func init() {

	const targetURL = "http://www.chronopost.fr/transport-express/livraison-colis/accueil/suivi?appid=9680_718&appparams=http%3A%2F%2Fwww.chronopost.fr%3A54711%2Fwebclipping%2Fservlet%2Fwebclip%3Fjahia_url_web_clipping%3Dhttp%3A%2F%2Flocalhost%3A54702%2Fexpedier%2FinputLTNumbers.do"

	RegisterCarrier(GenericCarrier{
		name: "Chronopost",
		matchPackage: func(p PackageID) bool {
			return true
		},
		getPackageInfo: func(p PackageID) (*PackageInfo, error) {
			resp, err := http.PostForm(targetURL, url.Values{"chronoNumbers": {string(p)}})
			if err != nil {
				return nil, err
			}

			var result struct {
				Info string `gostruct:"div.numeroColi2"`
			}

			if err := gostruct.PopulateFromResponse(&result, resp); err != nil {
				return nil, err
			}

			parts := strings.Split(result.Info, "\"")

			info := PackageInfo{
				PackageID: p,
				Info:      parts[1],
			}

			return &info, nil
		},
	})
}<commit_msg>chronopost: don't crash on bad data<commit_after>package wms

import (
	"net/http"
	"net/url"
	"strings"

	"github.com/bfontaine/gostruct"
)

func init() {

	const targetURL = "http://www.chronopost.fr/transport-express/livraison-colis/accueil/suivi?appid=9680_718&appparams=http%3A%2F%2Fwww.chronopost.fr%3A54711%2Fwebclipping%2Fservlet%2Fwebclip%3Fjahia_url_web_clipping%3Dhttp%3A%2F%2Flocalhost%3A54702%2Fexpedier%2FinputLTNumbers.do"

	RegisterCarrier(GenericCarrier{
		name: "Chronopost",
		matchPackage: func(p PackageID) bool {
			return true
		},
		getPackageInfo: func(p PackageID) (*PackageInfo, error) {
			resp, err := http.PostForm(targetURL, url.Values{"chronoNumbers": {string(p)}})
			if err != nil {
				return nil, err
			}

			var result struct {
				Info string `gostruct:"div.numeroColi2"`
			}

			if err := gostruct.PopulateFromResponse(&result, resp); err != nil {
				return nil, err
			}

			parts := strings.Split(result.Info, "\"")

			var text string
			if len(parts) > 2 {
				text = parts[1]
			} else {
				text = result.Info
			}

			info := PackageInfo{
				PackageID: p,
				Info:      text,
			}

			return &info, nil
		},
	})
}
{'fraction_non_alphanumeric': 0.139555958314454, 'fraction_numerical': 0.031264159492523785, 'mean_word_length': 3.972972972972973, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5728671', 'n_tokens_mistral': 1001, 'n_tokens_neox': 850, 'n_words': 142}