Skip to content

Commit

Permalink
fix: fix galicia2 script
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Nov 25, 2024
1 parent 71a347d commit 32c5fab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions scripts/galicia2/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var Descriptor = &core.ScriptDescriptor{
if _, ok := options.(*optionsGalicia2); ok {
return &scriptGalicia2{
name: name,
listURL: "http://saih.chminosil.es/index.php?url=/datos/resumen_excel",
gaugeURLFormat: "http://saih.chminosil.es/index.php?url=/datos/ficha/estacion:%s",
listURL: "https://saih.chminosil.es/index.php?url=/datos/resumen_excel",
gaugeURLFormat: "https://saih.chminosil.es/index.php?url=/datos/ficha/estacion:%s",
}, nil
}
return nil, fmt.Errorf("failed to cast %T", optionsGalicia2{})
Expand Down
16 changes: 13 additions & 3 deletions scripts/galicia2/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"fmt"
"html"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -67,11 +69,19 @@ func prettyName(name string) string {
func (s *scriptGalicia2) parseTable() ([]item, error) {
var result []item
if !s.skipCookies {
err := core.Client.EnsureCookie("http://saih.chminosil.es", false)
if err != nil {
return result, err
if u, err := url.Parse(s.listURL); err == nil {
webRoot := fmt.Sprintf("%s://%s", u.Scheme, u.Host)
if err := core.Client.EnsureCookie(webRoot, false); err != nil {
return result, err
}
core.Client.Jar.SetCookies(u, []*http.Cookie{
{Name: "lang", Value: "es"},
})
} else {
return result, fmt.Errorf("failed to parse list url %s: %w", s.listURL, err)
}
}

resp, err := core.Client.Get(s.listURL, nil)
if err != nil {
return result, err
Expand Down

0 comments on commit 32c5fab

Please sign in to comment.