Skip to content

Commit

Permalink
Merge pull request #34 from tgoulder4/32-2-lowercase-findtrains-param…
Browse files Browse the repository at this point in the history
…eter

32 2 lowercase findtrains parameter
  • Loading branch information
tgoulder4 committed Aug 27, 2023
2 parents 025c030 + 859a6c0 commit 8069544
Show file tree
Hide file tree
Showing 30 changed files with 23,619 additions and 26,270 deletions.
10 changes: 5 additions & 5 deletions dist/src/findTrains.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const findStationNameAndCode = (stationNameOrCode) => {
// console.log(
// `stationName: ${stationName}, stationCode: ${stationCode}, stationNameOrCode: ${stationNameOrCode}`
// );
const match = stationNameOrCode.match(/^[A-Z]{3}$/);
const match = stationNameOrCode.trim().match(/^[A-Za-z]{3}$/);
if (match) {
// console.log(`match: ${match}`);
const jsonMatch = stationLocations[match[0]];
const jsonMatch = stationLocations[match[0].toUpperCase()];
if (jsonMatch) {
stationName = stationLocations[match[0]].station_name;
stationCode = match[0];
stationName = jsonMatch.station_name;
stationCode = match[0].toUpperCase();
}
else {
stationName = null;
Expand Down Expand Up @@ -80,7 +80,7 @@ function findTrains(stationNameOrCode, dateOfDeparture = getCurrentDayTime("YYYY
};
const services = [];
//rate limiter
yield new Promise((r) => setTimeout(r, 500));
// await new Promise((r) => setTimeout(r, 500));
const res = yield fetch(`https://www.realtimetrains.co.uk/search/detailed/gb-nr:${stationCode}/${dateOfDeparture}/${timeOfDeparture}`);
const $ = cheerio.load(yield res.text());
for (const el of $("a.service").toArray()) {
Expand Down
20 changes: 10 additions & 10 deletions dist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
trackTrain: trackTrain_1.trackTrain,
};
// const util = require("util");
// trackTrain("G59487").then((emitter) => {
// emitter.on("journey", (data) => {
// console.log(util.inspect(data, false, null, true));
// });
// emitter.on("information", (data) => {
// console.log(util.inspect(data, false, null, true));
// });
// });
// // trackTrain("G59487").then((emitter) => {
// // emitter.on("journey", (data) => {
// // console.log(util.inspect(data, false, null, true));
// // });
// // emitter.on("information", (data) => {
// // console.log(util.inspect(data, false, null, true));
// // });
// // });
// (async () => {
// const data = await findTrains("BHM");
// console.log(util.inspect(data, false, null, true));
// const data = await getHTML("testServiceID", "2023-01-01");
// console.log(`DATA IS THIS: ${data}`);
// })();
Loading

0 comments on commit 8069544

Please sign in to comment.