-
Notifications
You must be signed in to change notification settings - Fork 1
/
antigua.go
69 lines (58 loc) · 1.43 KB
/
antigua.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package multasgt
import (
"fmt"
"net/http"
"net/url"
"github.com/PuerkitoBio/goquery"
)
// Ensure interface implementation.
var _ TicketChecker = &Antigua{}
const (
antiguaURL = "http://muniantigua.com/sql/pmt/buscar.php"
antiguaEntity = "ANTIGUA"
)
// Antigua implementation.
type Antigua struct {
Client *http.Client
}
// Check retrieves all tickes and aditional information.
func (a *Antigua) Check(plateType, plateNumber string) ([]Ticket, error) {
resp, err := a.Client.PostForm(antiguaURL, url.Values{
"placa_total": {fmt.Sprintf("%s-%s", plateType, plateNumber)},
})
if err != nil {
return nil, err
}
doc, err := goquery.NewDocumentFromResponse(resp)
if err != nil {
return nil, err
}
var tickets []Ticket
doc.Find(`.main table:last-child tbody tr`).Each(func(idx int, sel *goquery.Selection) {
if idx == 0 {
return
}
if sel.Children().Length() == 0 {
return
}
ticket := Ticket{Entity: antiguaEntity}
sel.Children().Each(func(cIdx int, cSel *goquery.Selection) {
switch cIdx {
case 0:
ticket.ID = CleanStrings(cSel.First().Text())
case 1:
ticket.Date = CleanStrings(cSel.First().Text())
case 2:
ticket.Location = CleanStrings(cSel.Text())
case 3:
ticket.Info = CleanStrings(cSel.Text())
case 5:
ticket.Amount = CleanStrings(cSel.Text())
case 7:
ticket.Total = CleanStrings(cSel.Text())
tickets = append(tickets, ticket)
}
})
})
return tickets, nil
}