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"
|
||||
],
|
||||
"properties": {
|
||||
"backToSg": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"contact": {
|
||||
"type": "string",
|
||||
"example": "+6512345678"
|
||||
@@ -463,7 +467,13 @@ const docTemplate = `{
|
||||
},
|
||||
"ktmtrainbot.BookingResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"backToSg"
|
||||
],
|
||||
"properties": {
|
||||
"backToSg": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"contact": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -425,6 +425,10 @@
|
||||
"travelDate"
|
||||
],
|
||||
"properties": {
|
||||
"backToSg": {
|
||||
"type": "boolean",
|
||||
"example": false
|
||||
},
|
||||
"contact": {
|
||||
"type": "string",
|
||||
"example": "+6512345678"
|
||||
@@ -455,7 +459,13 @@
|
||||
},
|
||||
"ktmtrainbot.BookingResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"backToSg"
|
||||
],
|
||||
"properties": {
|
||||
"backToSg": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"contact": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -23,6 +23,9 @@ definitions:
|
||||
type: object
|
||||
ktmtrainbot.BookingCreateRequest:
|
||||
properties:
|
||||
backToSg:
|
||||
example: false
|
||||
type: boolean
|
||||
contact:
|
||||
example: "+6512345678"
|
||||
type: string
|
||||
@@ -53,6 +56,8 @@ definitions:
|
||||
type: object
|
||||
ktmtrainbot.BookingResponse:
|
||||
properties:
|
||||
backToSg:
|
||||
type: boolean
|
||||
contact:
|
||||
type: string
|
||||
gender:
|
||||
@@ -71,6 +76,8 @@ definitions:
|
||||
type: string
|
||||
travelDate:
|
||||
type: string
|
||||
required:
|
||||
- backToSg
|
||||
type: object
|
||||
ktmtrainbot.ServerTimeResponse:
|
||||
properties:
|
||||
|
||||
@@ -167,12 +167,13 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
||||
passport := job.Passport
|
||||
passportExpiry := job.PassportExpiry.Format("2 Jan 2006")
|
||||
contact := job.Contact
|
||||
reverse := job.BackToSg
|
||||
|
||||
threadCount := 10
|
||||
for i := 0; i < threadCount; i++ {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
go func() {
|
||||
currPage := getBookingSlots(browser, onwardDate)
|
||||
currPage := getBookingSlots(browser, onwardDate, reverse)
|
||||
log.Println("Booking page loaded.")
|
||||
|
||||
currPage = selectBookingSlot(getBookingSlotCtx, currPage, timeCode)
|
||||
@@ -272,7 +273,7 @@ func ktmTrainLogin(browser *rod.Browser, username string, password string) *rod.
|
||||
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.MustWaitLoad()
|
||||
|
||||
@@ -295,7 +296,11 @@ func getBookingSlots(browser *rod.Browser, onwardDate string) *rod.Page {
|
||||
woodlandsData := page.MustElement("#ToStationData").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()
|
||||
|
||||
return page
|
||||
|
||||
@@ -18,6 +18,7 @@ func (env *Env) createBooking(
|
||||
passport string,
|
||||
passportExpiry time.Time,
|
||||
contact string,
|
||||
backToSg bool,
|
||||
) (*Booking, error) {
|
||||
var newBooking Booking
|
||||
|
||||
@@ -28,6 +29,8 @@ func (env *Env) createBooking(
|
||||
newBooking.Gender = gender
|
||||
newBooking.Passport = passport
|
||||
newBooking.PassportExpiry = passportExpiry
|
||||
newBooking.Contact = contact
|
||||
newBooking.BackToSg = backToSg
|
||||
|
||||
newBooking.Status = "pending"
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ type Booking struct {
|
||||
Passport string
|
||||
PassportExpiry time.Time // Only date matters
|
||||
Contact string // +6512345678
|
||||
BackToSg bool // true/false
|
||||
Status string // "success", "error", "pending", "running"
|
||||
}
|
||||
|
||||
@@ -34,6 +35,7 @@ type BookingCreateRequest struct {
|
||||
Passport string `json:"passport" validate:"required"`
|
||||
PassportExpiry time.Time `json:"passportExpiry" validate:"required" swaggertype:"string" format:"date-time"`
|
||||
Contact string `json:"contact" validate:"required,e164" swaggertype:"string" example:"+6512345678"`
|
||||
BackToSg bool `json:"backToSg" swaggertype:"boolean" example:"false"`
|
||||
}
|
||||
|
||||
type BookingResponse struct {
|
||||
@@ -46,6 +48,7 @@ type BookingResponse struct {
|
||||
PassportExpiry time.Time `json:"passportExpiry"`
|
||||
Contact string `json:"contact"`
|
||||
Status string `json:"status"`
|
||||
BackToSg bool `json:"backToSg" validate:"required"`
|
||||
}
|
||||
|
||||
type BookingListResponse []BookingResponse
|
||||
|
||||
@@ -81,6 +81,7 @@ func (env *Env) createBookingRoute(w http.ResponseWriter, r *http.Request) {
|
||||
data.Passport,
|
||||
data.PassportExpiry,
|
||||
data.Contact,
|
||||
data.BackToSg,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user