Skip to content

Commit

Permalink
Merge pull request #2 from Dojeto/main
Browse files Browse the repository at this point in the history
PNR Status
  • Loading branch information
Dojeto authored Mar 18, 2024
2 parents abe57df + 8455272 commit 6dcb15a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions routes/getTrains.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,20 @@ router.get("/stationLive", async (req, resp) => {
}
});

router.get("/pnrstatus",async(req,resp)=>{
const pnrnumber = req.query.pnr;
try {
//inspired from RobinKumar5986 (pull request #3)
let URL_Train = `https://www.confirmtkt.com/pnr-status/${pnrnumber}`
let response = await fetch(URL_Train);
let data = await response.text();
let json = prettify.PnrStatus(data);
resp.send(json)
} catch (error) {
console.log(error)
}

})


export default router;
11 changes: 11 additions & 0 deletions utils/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ class Prettify {
return retval;
}

PnrStatus(string){
let retval = {};
var pattern = /data\s*=\s*({.*?;)/
let match = string.match(pattern)[0].slice(7,-1)
let data = JSON.parse(match)
retval["success"] = true;
retval["time_stamp"] = Date.now();
retval["data"] = data
return retval
}

CheckTrain(string) {
try {
let obj = {};
Expand Down

0 comments on commit 6dcb15a

Please sign in to comment.