Skip to content

Commit

Permalink
feat: migrate direction enum to JToW and WToJ confirming to server
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Dec 13, 2023
1 parent 62848e6 commit 513fa1b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
17 changes: 6 additions & 11 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class Cli {
"Start repeatedly poll and watch for changes for a fixed day and direction",
)
.option("-d, --date <date>", "Date to poll")
.option(
"-f, --from <from>",
`Direction to poll, either 'JB' or 'Woodlands'`,
)
.option("-f, --from <from>", `Direction to poll, either 'JToW' or 'WToJ'`)
.option(
"-i, --interval <interval>",
`Interval to poll in seconds, default 180`,
Expand All @@ -51,12 +48,14 @@ class Cli {
interval: string;
}) => {
await tracer.startActiveSpan("watch", async (span) => {
const [day, month, year] = date.split("-");
date = `${year}-${month}-${day}`;
const d = new Date(date);
const i = parseInt(interval);
if (isNaN(i)) throw new Error("Interval must be a number");
if (from !== "JB" && from !== "Woodlands")
throw new Error("From must be either 'JB' or 'Woodlands'");
const f = from as "JB" | "Woodlands";
if (from !== "JToW" && from !== "WToJ")
throw new Error("From must be either 'JToW' or 'WToJ'");
const f = from as "JToW" | "WToJ";
const a = await this.builder.BuildFixed(f, d);
const loopDuration = i * 1000;
const startTime = Date.now();
Expand All @@ -75,10 +74,6 @@ class Cli {
while (true) {
const currentTime = Date.now();
const elapsedTime = currentTime - startTime;
this.logger.info(
{ index: index++, elapsedTime, loopDuration },
"Running search",
);
if (elapsedTime >= loopDuration) break;

// run the searcher
Expand Down
2 changes: 1 addition & 1 deletion src/domain/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface TrainSchedule {
min_fare: string;
}

type From = "JB" | "Woodlands";
type From = "JToW" | "WToJ";

interface IScheduleSearcher {
Search(from: From, date: Date): Promise<TrainSchedule[]>;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/search_core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SearchCore {
const referer = "https://shuttleonline.ktmb.com.my/Home/Shuttle";

const [FromStationData, ToStationData, FromStationId, ToStationId] =
from === "JB"
from === "JToW"
? [jbToken, woodlandToken, JB_STATION_ID, WOODLANDS_STATION_ID]
: [woodlandToken, jbToken, WOODLANDS_STATION_ID, JB_STATION_ID];

Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ cfg.caches.forEach((v, k) => {

if (v.tls) o.tls = {};

console.log(o);

const redis = new Redis(o);
container.register(svc[k + "cache"], { useValue: redis });
});
Expand Down

0 comments on commit 513fa1b

Please sign in to comment.