-
Notifications
You must be signed in to change notification settings - Fork 1
/
emixtra.go
59 lines (52 loc) · 1.84 KB
/
emixtra.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
package multasgt
import (
"net/http"
"net/url"
"github.com/PuerkitoBio/goquery"
)
// Ensure interface implementation.
var _ TicketChecker = &Emixtra{}
const (
emixtraURL = "https://consultas.munimixco.gob.gt/pvisa/emixtra"
exmitraEntity = "EMIXTRA"
)
// Emixtra implementation.
type Emixtra struct {
Client *http.Client
}
// Check retrieves all tickes and aditional information.
func (e *Emixtra) Check(plateType, plateNumber string) ([]Ticket, error) {
resp, err := e.Client.PostForm(emixtraURL, url.Values{
"tPlaca": {plateType},
"placa": {plateNumber},
"estado": {"0"},
})
if err != nil {
return nil, err
}
var tickets []Ticket
doc, err := goquery.NewDocumentFromResponse(resp)
if err != nil {
return nil, err
}
rows := doc.Find(".row > .col-md-8.col-xs-10> .panel.panel-primary")
var ticket Ticket
rows.Each(func(idx int, sel *goquery.Selection) {
// Ommit header info
if idx == 0 {
return
}
ticket = Ticket{Entity: exmitraEntity}
ticket.ID = CleanStrings(sel.Find(".panel-heading > .row > .col-md-5.col-xs-5").Text())
ticket.Date = CleanStrings(sel.Find(".panel-heading > .row > .col-md-6.col-xs-5").Text())
ticket.Location = CleanStrings(sel.Find(".panel-body > .row:nth-of-type(1) > .col-md-3.col-xs-9").Text())
ticket.Info = CleanStrings(sel.Find(".panel-body > .row:nth-of-type(3) > .col-md-5.col-xs-9").Text())
ticket.Amount = CleanStrings(sel.Find(".panel-body > .row:nth-of-type(6) > div:nth-of-type(1)").Text())
ticket.Discount = CleanStrings(sel.Find(".panel-body > .row:nth-of-type(6) > div:nth-of-type(2)").Text())
ticket.Total = CleanStrings(sel.Find(".panel-body > .row:nth-of-type(6) > div:nth-of-type(3)").Text())
_photo := sel.Find(".panel-body > .row:nth-of-type(4) > .col-md-5 > img")
ticket.Photo = GetAttribute("src", _photo.Get(0))
tickets = append(tickets, ticket)
})
return tickets, nil
}