From d1025241468cbff356aeb94c84ec2f2933d7cf85 Mon Sep 17 00:00:00 2001 From: Abdussamet Kocak Date: Thu, 6 Apr 2023 12:05:18 +0200 Subject: [PATCH] fix(pkg/diyanet): Handle updates to the page structure --- pkg/diyanet/scraper.go | 12 ++++++------ pkg/diyanet/scraper_test.go | 14 ++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/diyanet/scraper.go b/pkg/diyanet/scraper.go index c4f7721..fee0fe7 100644 --- a/pkg/diyanet/scraper.go +++ b/pkg/diyanet/scraper.go @@ -54,12 +54,12 @@ func (d Provider) Get(ctx context.Context, location string) ([]prayer.Times, err row := prayer.Times{ Date: parsedDate.Format(time.DateOnly), - Fajr: el.Find("td:nth-of-type(2)").Text(), - Sunrise: el.Find("td:nth-of-type(3)").Text(), - Dhuhr: el.Find("td:nth-of-type(4)").Text(), - Asr: el.Find("td:nth-of-type(5)").Text(), - Maghrib: el.Find("td:nth-of-type(6)").Text(), - Isha: el.Find("td:nth-of-type(7)").Text(), + Fajr: el.Find("td:nth-of-type(3)").Text(), + Sunrise: el.Find("td:nth-of-type(4)").Text(), + Dhuhr: el.Find("td:nth-of-type(5)").Text(), + Asr: el.Find("td:nth-of-type(6)").Text(), + Maghrib: el.Find("td:nth-of-type(7)").Text(), + Isha: el.Find("td:nth-of-type(8)").Text(), } times = append(times, row) }) diff --git a/pkg/diyanet/scraper_test.go b/pkg/diyanet/scraper_test.go index ee013e0..6a37f81 100644 --- a/pkg/diyanet/scraper_test.go +++ b/pkg/diyanet/scraper_test.go @@ -4,7 +4,6 @@ import ( "context" "strings" "testing" - "time" "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" @@ -27,6 +26,7 @@ const mockHtml = ` Gregorian Calendar Date + Hijri Date Fajr Sun Dhuhr @@ -38,6 +38,7 @@ const mockHtml = ` 04.03.2023 + ... 05:48 07:11 13:05 @@ -47,6 +48,7 @@ const mockHtml = ` 05.03.2023 + ... 05:46 07:09 13:04 @@ -76,7 +78,7 @@ func TestDiyanet_Get(t *testing.T) { expected := []prayer.Times{ { - Date: time.Date(2023, time.March, 4, 0, 0, 0, 0, time.UTC), + Date: "2023-03-04", Fajr: "05:48", Sunrise: "07:11", Dhuhr: "13:05", @@ -85,7 +87,7 @@ func TestDiyanet_Get(t *testing.T) { Isha: "20:06", }, { - Date: time.Date(2023, time.March, 5, 0, 0, 0, 0, time.UTC), + Date: "2023-03-05", Fajr: "05:46", Sunrise: "07:09", Dhuhr: "13:04", @@ -105,9 +107,13 @@ func TestDiyanet_Get(t *testing.T) { d := Provider{ FetcherFunc: net.GetParsed, } - times, err := d.Get(context.Background(), "9205") + times, err := d.Get(context.Background(), "11104") assert.NoError(t, err) assert.Greater(t, len(times), 1) assert.NotZero(t, times[0].Date) + + for _, it := range times { + t.Logf("%+v", it) + } }) }