chore: add some more test-files and make code more stable
This commit is contained in:
+11
-15
@@ -62,7 +62,7 @@ func Start() error {
|
||||
})
|
||||
|
||||
data, err := json.Marshal(&Events{
|
||||
Start: time.Time(events[0].Date).Format("2006-01-02"),
|
||||
Start: events[0].Date,
|
||||
Events: events,
|
||||
})
|
||||
buff := bytes.NewBuffer(data)
|
||||
@@ -97,7 +97,7 @@ func parse(url string, opts ...colly.CollectorOption) ([]Event, error) {
|
||||
}
|
||||
})
|
||||
collector.OnHTML("h2", func(e *colly.HTMLElement) {
|
||||
if e.Text == "Inga danser funna" {
|
||||
if e.Text == "Inga danser hittades" {
|
||||
empty = true
|
||||
}
|
||||
})
|
||||
@@ -108,11 +108,9 @@ func parse(url string, opts ...colly.CollectorOption) ([]Event, error) {
|
||||
if !empty {
|
||||
if len(headers) == 0 {
|
||||
e.ForEach("th", func(i int, cell *colly.HTMLElement) {
|
||||
if len(strings.TrimSpace(cell.Text)) > 0 {
|
||||
headers = append(headers, strings.TrimSpace(cell.Text))
|
||||
if cell.Attr("colspan") == "2" {
|
||||
headers = append(headers, strings.TrimSpace(cell.Text))
|
||||
if cell.Attr("colspan") == "2" {
|
||||
headers = append(headers, strings.TrimSpace(cell.Text))
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -121,7 +119,8 @@ func parse(url string, opts ...colly.CollectorOption) ([]Event, error) {
|
||||
var parts []string
|
||||
e.ForEachWithBreak("td", func(i int, cell *colly.HTMLElement) bool {
|
||||
if len(cell.Attr("colspan")) > 0 {
|
||||
dateString := strings.TrimSpace(cell.Text)
|
||||
re := regexp.MustCompile(`\s+`)
|
||||
dateString := re.ReplaceAllString(strings.TrimSpace(cell.Text), " ")
|
||||
date, err := monday.ParseInLocation("January", dateString, now.Location(), monday.LocaleSvSE)
|
||||
if err != nil {
|
||||
date, err = monday.ParseInLocation("January 2006", dateString, now.Location(), monday.LocaleSvSE)
|
||||
@@ -140,21 +139,18 @@ func parse(url string, opts ...colly.CollectorOption) ([]Event, error) {
|
||||
return true
|
||||
})
|
||||
if len(parts) > 0 {
|
||||
var fields []string
|
||||
for i, p := range parts {
|
||||
if i <= 2 || i == len(parts)-1 || len(p) != 0 {
|
||||
fields = append(fields, p)
|
||||
}
|
||||
}
|
||||
fields := parts
|
||||
|
||||
if len(fields) >= 3 {
|
||||
band := value("Dansband", headers, fields)
|
||||
if regexp.MustCompile(`.*\d\.\d.*`).MatchString(band) {
|
||||
fmt.Printf("Removing field 2\n")
|
||||
fields = append(fields[:2], fields[3:]...)
|
||||
}
|
||||
date := value("Datum", headers, fields)
|
||||
day, err := strconv.Atoi(date)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to parse '%s' as an int\n", date)
|
||||
return
|
||||
}
|
||||
event := Event{
|
||||
@@ -203,8 +199,8 @@ func ignored(class string, styles []string) bool {
|
||||
}
|
||||
|
||||
type Events struct {
|
||||
Start string `json:"start"`
|
||||
Events []Event `json:"events"`
|
||||
Start LocalDate `json:"start"`
|
||||
Events []Event `json:"events"`
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
|
||||
Reference in New Issue
Block a user