Feat(booking): Added backtosg field
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
This commit is contained in:
@@ -433,6 +433,10 @@ const docTemplate = `{
|
|||||||
"travelDate"
|
"travelDate"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"backToSg": {
|
||||||
|
"type": "boolean",
|
||||||
|
"example": false
|
||||||
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "+6512345678"
|
"example": "+6512345678"
|
||||||
@@ -463,7 +467,13 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"ktmtrainbot.BookingResponse": {
|
"ktmtrainbot.BookingResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"backToSg"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"backToSg": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -425,6 +425,10 @@
|
|||||||
"travelDate"
|
"travelDate"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"backToSg": {
|
||||||
|
"type": "boolean",
|
||||||
|
"example": false
|
||||||
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "+6512345678"
|
"example": "+6512345678"
|
||||||
@@ -455,7 +459,13 @@
|
|||||||
},
|
},
|
||||||
"ktmtrainbot.BookingResponse": {
|
"ktmtrainbot.BookingResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"backToSg"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"backToSg": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
ktmtrainbot.BookingCreateRequest:
|
ktmtrainbot.BookingCreateRequest:
|
||||||
properties:
|
properties:
|
||||||
|
backToSg:
|
||||||
|
example: false
|
||||||
|
type: boolean
|
||||||
contact:
|
contact:
|
||||||
example: "+6512345678"
|
example: "+6512345678"
|
||||||
type: string
|
type: string
|
||||||
@@ -53,6 +56,8 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
ktmtrainbot.BookingResponse:
|
ktmtrainbot.BookingResponse:
|
||||||
properties:
|
properties:
|
||||||
|
backToSg:
|
||||||
|
type: boolean
|
||||||
contact:
|
contact:
|
||||||
type: string
|
type: string
|
||||||
gender:
|
gender:
|
||||||
@@ -71,6 +76,8 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
travelDate:
|
travelDate:
|
||||||
type: string
|
type: string
|
||||||
|
required:
|
||||||
|
- backToSg
|
||||||
type: object
|
type: object
|
||||||
ktmtrainbot.ServerTimeResponse:
|
ktmtrainbot.ServerTimeResponse:
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
@@ -167,12 +167,13 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
|||||||
passport := job.Passport
|
passport := job.Passport
|
||||||
passportExpiry := job.PassportExpiry.Format("2 Jan 2006")
|
passportExpiry := job.PassportExpiry.Format("2 Jan 2006")
|
||||||
contact := job.Contact
|
contact := job.Contact
|
||||||
|
reverse := job.BackToSg
|
||||||
|
|
||||||
threadCount := 10
|
threadCount := 10
|
||||||
for i := 0; i < threadCount; i++ {
|
for i := 0; i < threadCount; i++ {
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
go func() {
|
go func() {
|
||||||
currPage := getBookingSlots(browser, onwardDate)
|
currPage := getBookingSlots(browser, onwardDate, reverse)
|
||||||
log.Println("Booking page loaded.")
|
log.Println("Booking page loaded.")
|
||||||
|
|
||||||
currPage = selectBookingSlot(getBookingSlotCtx, currPage, timeCode)
|
currPage = selectBookingSlot(getBookingSlotCtx, currPage, timeCode)
|
||||||
@@ -272,7 +273,7 @@ func ktmTrainLogin(browser *rod.Browser, username string, password string) *rod.
|
|||||||
return page
|
return page
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBookingSlots(browser *rod.Browser, onwardDate string) *rod.Page {
|
func getBookingSlots(browser *rod.Browser, onwardDate string, reverse bool) *rod.Page {
|
||||||
page := browser.MustPage("https://shuttleonline.ktmb.com.my/Home/Shuttle")
|
page := browser.MustPage("https://shuttleonline.ktmb.com.my/Home/Shuttle")
|
||||||
page.MustWaitLoad()
|
page.MustWaitLoad()
|
||||||
|
|
||||||
@@ -295,7 +296,11 @@ func getBookingSlots(browser *rod.Browser, onwardDate string) *rod.Page {
|
|||||||
woodlandsData := page.MustElement("#ToStationData").MustAttribute("value")
|
woodlandsData := page.MustElement("#ToStationData").MustAttribute("value")
|
||||||
woodlandsID := page.MustElement("#ToStationId").MustAttribute("value")
|
woodlandsID := page.MustElement("#ToStationId").MustAttribute("value")
|
||||||
|
|
||||||
sensitiveCustomForm(page, *woodlandsData, *jBSentralData, *woodlandsID, *jBSentralID, onwardDate, passengerCountStr, *requestVerificationToken)
|
if !reverse {
|
||||||
|
sensitiveCustomForm(page, *woodlandsData, *jBSentralData, *woodlandsID, *jBSentralID, onwardDate, passengerCountStr, *requestVerificationToken)
|
||||||
|
} else {
|
||||||
|
sensitiveCustomForm(page, *jBSentralData, *woodlandsData, *jBSentralID, *woodlandsID, onwardDate, passengerCountStr, *requestVerificationToken)
|
||||||
|
}
|
||||||
page.MustWaitLoad()
|
page.MustWaitLoad()
|
||||||
|
|
||||||
return page
|
return page
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ func (env *Env) createBooking(
|
|||||||
passport string,
|
passport string,
|
||||||
passportExpiry time.Time,
|
passportExpiry time.Time,
|
||||||
contact string,
|
contact string,
|
||||||
|
backToSg bool,
|
||||||
) (*Booking, error) {
|
) (*Booking, error) {
|
||||||
var newBooking Booking
|
var newBooking Booking
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ func (env *Env) createBooking(
|
|||||||
newBooking.Gender = gender
|
newBooking.Gender = gender
|
||||||
newBooking.Passport = passport
|
newBooking.Passport = passport
|
||||||
newBooking.PassportExpiry = passportExpiry
|
newBooking.PassportExpiry = passportExpiry
|
||||||
|
newBooking.Contact = contact
|
||||||
|
newBooking.BackToSg = backToSg
|
||||||
|
|
||||||
newBooking.Status = "pending"
|
newBooking.Status = "pending"
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type Booking struct {
|
|||||||
Passport string
|
Passport string
|
||||||
PassportExpiry time.Time // Only date matters
|
PassportExpiry time.Time // Only date matters
|
||||||
Contact string // +6512345678
|
Contact string // +6512345678
|
||||||
|
BackToSg bool // true/false
|
||||||
Status string // "success", "error", "pending", "running"
|
Status string // "success", "error", "pending", "running"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ type BookingCreateRequest struct {
|
|||||||
Passport string `json:"passport" validate:"required"`
|
Passport string `json:"passport" validate:"required"`
|
||||||
PassportExpiry time.Time `json:"passportExpiry" validate:"required" swaggertype:"string" format:"date-time"`
|
PassportExpiry time.Time `json:"passportExpiry" validate:"required" swaggertype:"string" format:"date-time"`
|
||||||
Contact string `json:"contact" validate:"required,e164" swaggertype:"string" example:"+6512345678"`
|
Contact string `json:"contact" validate:"required,e164" swaggertype:"string" example:"+6512345678"`
|
||||||
|
BackToSg bool `json:"backToSg" swaggertype:"boolean" example:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BookingResponse struct {
|
type BookingResponse struct {
|
||||||
@@ -46,6 +48,7 @@ type BookingResponse struct {
|
|||||||
PassportExpiry time.Time `json:"passportExpiry"`
|
PassportExpiry time.Time `json:"passportExpiry"`
|
||||||
Contact string `json:"contact"`
|
Contact string `json:"contact"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
BackToSg bool `json:"backToSg" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BookingListResponse []BookingResponse
|
type BookingListResponse []BookingResponse
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ func (env *Env) createBookingRoute(w http.ResponseWriter, r *http.Request) {
|
|||||||
data.Passport,
|
data.Passport,
|
||||||
data.PassportExpiry,
|
data.PassportExpiry,
|
||||||
data.Contact,
|
data.Contact,
|
||||||
|
data.BackToSg,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user