fix(pkg/diyanet): Handle updates to the page structure

master
Abdussamet Kocak 3 years ago
parent 9530733291
commit d102524146

@ -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)
})

@ -4,7 +4,6 @@ import (
"context"
"strings"
"testing"
"time"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
@ -27,6 +26,7 @@ const mockHtml = `
<thead>
<tr>
<th>Gregorian Calendar Date</th>
<th>Hijri Date</th>
<th>Fajr</th>
<th>Sun</th>
<th>Dhuhr</th>
@ -38,6 +38,7 @@ const mockHtml = `
<tbody>
<tr>
<td>04.03.2023</td>
<td>...</td>
<td>05:48</td>
<td>07:11</td>
<td>13:05</td>
@ -47,6 +48,7 @@ const mockHtml = `
</tr>
<tr>
<td>05.03.2023</td>
<td>...</td>
<td>05:46</td>
<td>07:09</td>
<td>13:04</td>
@ -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)
}
})
}

Loading…
Cancel
Save