mirror of
https://github.com/aykhans/azal-bot.git
synced 2025-04-20 22:07:16 +00:00
✨ add flight classes to notifications
This commit is contained in:
parent
1efac78b98
commit
4dd151bc10
51
main.go
51
main.go
@ -16,7 +16,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
RequestURL = "https://azal.az/book/api/flights/search/by-deeplink"
|
RequestURL = "https://azal.az/book/api/flights/search/by-deeplink"
|
||||||
TelegramAPIURL = "https://api.telegram.org/bot%s/sendMessage"
|
TelegramAPIURL = "https://api.telegram.org/bot%s/sendMessage"
|
||||||
Version = "0.2.0"
|
Version = "0.2.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -52,7 +52,13 @@ func Colored(color string, a ...any) string {
|
|||||||
return color + fmt.Sprint(a...) + Colors.reset
|
return color + fmt.Sprint(a...) + Colors.reset
|
||||||
}
|
}
|
||||||
|
|
||||||
type AvialableFlights map[string][]time.Time
|
type AvialableFlight struct {
|
||||||
|
Economy bool
|
||||||
|
Business bool
|
||||||
|
DepartureDate time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type AvialableFlights map[string][]AvialableFlight
|
||||||
|
|
||||||
type TelegramRequest struct {
|
type TelegramRequest struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
@ -90,7 +96,17 @@ func (telegramRequest *TelegramRequest) sendTelegramFlightNotification(avialable
|
|||||||
for day, flights := range avialableFlights {
|
for day, flights := range avialableFlights {
|
||||||
message += fmt.Sprintf("%s\n-----------\n", day)
|
message += fmt.Sprintf("%s\n-----------\n", day)
|
||||||
for _, flight := range flights {
|
for _, flight := range flights {
|
||||||
message += fmt.Sprintf("%s\n", flight.Format("15:04:05"))
|
classes := ""
|
||||||
|
if flight.Economy {
|
||||||
|
classes += "Economy"
|
||||||
|
}
|
||||||
|
if flight.Business {
|
||||||
|
if classes != "" {
|
||||||
|
classes += ", "
|
||||||
|
}
|
||||||
|
classes += "Business"
|
||||||
|
}
|
||||||
|
message += fmt.Sprintf("%s (%s)\n", flight.DepartureDate.Format("15:04:05"), classes)
|
||||||
}
|
}
|
||||||
message += "\n"
|
message += "\n"
|
||||||
}
|
}
|
||||||
@ -155,9 +171,11 @@ type SuccessResponse struct {
|
|||||||
Search struct {
|
Search struct {
|
||||||
OptionSets []struct {
|
OptionSets []struct {
|
||||||
Options []struct {
|
Options []struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Available bool `json:"available"`
|
Available bool `json:"available"`
|
||||||
Route struct {
|
CheapestEconomySolutionId string `json:"cheapestEconomySolutionId"`
|
||||||
|
CheapestBusinessSolutionId string `json:"cheapestBusinessSolutionId"`
|
||||||
|
Route struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
DepartureDate ResponseTime `json:"departureDate"`
|
DepartureDate ResponseTime `json:"departureDate"`
|
||||||
} `json:"route"`
|
} `json:"route"`
|
||||||
@ -506,8 +524,25 @@ func startBot(botConfig *BotConfig, ifAvailable func(avialableFlights AvialableF
|
|||||||
if (departureDate.After(botConfig.FirstDate) || departureDate.Equal(botConfig.FirstDate)) &&
|
if (departureDate.After(botConfig.FirstDate) || departureDate.Equal(botConfig.FirstDate)) &&
|
||||||
(departureDate.Before(botConfig.LastDate) || departureDate.Equal(botConfig.LastDate)) {
|
(departureDate.Before(botConfig.LastDate) || departureDate.Equal(botConfig.LastDate)) {
|
||||||
|
|
||||||
avialableFlights[day] = append(avialableFlights[day], departureDate.Time)
|
avialableFlights[day] = append(
|
||||||
log.Println(Colored(Colors.Green, "Flight available for ", departureDate))
|
avialableFlights[day],
|
||||||
|
AvialableFlight{
|
||||||
|
Economy: option.CheapestEconomySolutionId != "",
|
||||||
|
Business: option.CheapestBusinessSolutionId != "",
|
||||||
|
DepartureDate: departureDate.Time,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
classes := ""
|
||||||
|
if option.CheapestEconomySolutionId != "" {
|
||||||
|
classes += "Economy"
|
||||||
|
}
|
||||||
|
if option.CheapestBusinessSolutionId != "" {
|
||||||
|
if classes != "" {
|
||||||
|
classes += ", "
|
||||||
|
}
|
||||||
|
classes += "Business"
|
||||||
|
}
|
||||||
|
log.Println(Colored(Colors.Green, "Flight available for ", departureDate, " (" + classes + ")"))
|
||||||
} else {
|
} else {
|
||||||
log.Println(Colored(Colors.Yellow, "No flights available for ", departureDate))
|
log.Println(Colored(Colors.Yellow, "No flights available for ", departureDate))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user