From 513fa1be7db94efd3a6d637e678809c108f931eb Mon Sep 17 00:00:00 2001 From: kirinnee Date: Wed, 13 Dec 2023 18:47:11 +0800 Subject: [PATCH] feat: migrate direction enum to JToW and WToJ confirming to server --- src/cli/cli.ts | 17 ++++++----------- src/domain/interface.ts | 2 +- src/domain/search_core.ts | 2 +- src/index.ts | 2 -- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 0dc6966..d4beb6f 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -32,10 +32,7 @@ class Cli { "Start repeatedly poll and watch for changes for a fixed day and direction", ) .option("-d, --date ", "Date to poll") - .option( - "-f, --from ", - `Direction to poll, either 'JB' or 'Woodlands'`, - ) + .option("-f, --from ", `Direction to poll, either 'JToW' or 'WToJ'`) .option( "-i, --interval ", `Interval to poll in seconds, default 180`, @@ -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(); @@ -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 diff --git a/src/domain/interface.ts b/src/domain/interface.ts index 6f45235..31d0c1d 100644 --- a/src/domain/interface.ts +++ b/src/domain/interface.ts @@ -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; diff --git a/src/domain/search_core.ts b/src/domain/search_core.ts index 3b3b3db..cbb5a3c 100644 --- a/src/domain/search_core.ts +++ b/src/domain/search_core.ts @@ -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]; diff --git a/src/index.ts b/src/index.ts index f0d9f80..912e2b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 }); });