Skip to content

Commit

Permalink
new compile
Browse files Browse the repository at this point in the history
do not know what will happen
  • Loading branch information
suryavaddiraju committed Apr 16, 2024
1 parent 265cdd5 commit 7439121
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
7 changes: 4 additions & 3 deletions index.mjs → index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {IRCTC as main_class} from "./lib/workings.mjs";
export default class IRCTC extends main_class{
import {main_class} from "./lib/workings.mjs"
class IRCTC extends main_class{
constructor(){
super();
}
Expand All @@ -12,4 +12,5 @@ export default class IRCTC extends main_class{
async pnr_status(params){
return await super.pnr_status(params);
}
};
};
export {IRCTC};
5 changes: 3 additions & 2 deletions lib/stations.json → lib/stations.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
const stations_list = [
"NDLS",
"MAS",
"HWH",
Expand Down Expand Up @@ -8488,4 +8488,5 @@
"ZP",
"ZNP",
"ZPR"
]
];
export {stations_list};
3 changes: 2 additions & 1 deletion lib/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'fs';
import readline from 'readline';
import {start_before_3_minutes} from "./time_work.mjs";
import { stations_list } from './stations.mjs';
async function verify_booking_params(params) {
let stationsList = JSON.parse(fs.readFileSync('./stations.json', 'utf-8'));
let stationsList = stations_list;
if (!params.quota || !params.class || !params.train_number || !params.journey_date || !params.from || !params.to || !params.userID || !params.password || !params.passengers || !params.UPI || !params.mobile_number) {
throw new Error("Missing parameters\nThe required parameters are quota, class, train_number, journey_date, from, to, userID, password, passengers, UPI, mobile_number");
}
Expand Down
3 changes: 2 additions & 1 deletion lib/workings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class IRCTC{
async send_login(){
const data = `grant_type=password&username=${this.username}&password=${this.password}&captcha=${this.captcha_answer}&uid=${this.captcha_status}&otpLogin=false&nlpIdentifier=&nlpAnswer=&nlpToken=&lso=&encodedPwd=true`;
const headers = main_headers.headers_4;
console.log(headers);
headers["Content-Length"] = data.length.toString();
await sleep_for_login(this.params.ticket_time);
const response = await this.axios_instance.post(
Expand Down Expand Up @@ -694,4 +695,4 @@ class IRCTC{
return data;
}
};
export {IRCTC};
export {IRCTC as main_class};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "irctc-api",
"description": "A package built on top of IRCTC Website APIs to make train tickets , managing user profile faster and simpler. Currently this package only works on NodeJs environment and we were not recommending this to use on browser or any other Javascript environment.",
"version": "1.0.2",
"version": "1.0.3",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down Expand Up @@ -31,6 +31,6 @@
"node": ">=20.0.0",
"npm": ">=10.0.0"
},
"main": "index.mjs",
"module": "index.js",
"type": "module"
}
38 changes: 38 additions & 0 deletions test/book_ticket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {IRCTC} from "../index.js";
const params = {
"UPI": "9876543210@ybl", // Your NPCI UPI VPA ID
"class": "2S", // class code such as 2A | 3A | SL | CC | 2S | FC | 1A
"quota": "GN", // GN | TQ | PT
"train_number": "17201", // 5 Digit Train Number
"from": "GNT", // Station code
"to": "PDKN", // Station code
"journey_date": "20240530", // YYYYMMDD
"mobile_number": "9876543210", // 10 Digit Mobile Number
"userID": "username_here", // Secret User ID
"password": "someSecret_here", // Secret Password
"passengers": [ // Passengers List - Max 4 members for Tatkal and 6 for General Quota
{
"age": "22", // Age of Passenger
"food": "", // Food Preference - Leave as Empty string, if food is not required
"name": "Virat Kohli", // Full Name of Passenger
"sex": "M" // Sex of Passenger - M | F
},
{
"age": "21", // Age of Passenger
"food": "", // Food Preference - Leave as Empty string, if food is not required
"name": "Anushka Sharma", // Full Name of Passenger
"sex": "F" // Sex of Passenger - M | F
}
]
};
async function custom_command_name(params) {
try{
const irctc = new IRCTC();
const response = await irctc.book(params);
console.log(response);
}
catch(e){
throw new Error(e);
}
};
await custom_command_name(params);

0 comments on commit 7439121

Please sign in to comment.