Skip to content

Commit

Permalink
Merge pull request #49 from suryavaddiraju/development
Browse files Browse the repository at this point in the history
v2.0.13
  • Loading branch information
suryavaddiraju committed May 14, 2024
2 parents 74910de + b0e99a1 commit f4d6e63
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ This Package uses [viu](https://github.com/atanunq/viu), A rust module uses iter

We use that for displaying captcha images on command line for login and bookings as to make your booking flow in a seamless way.

Hence you are required to download the viu executable file related to your OS and Processor Architecture from the [viu release Assets](https://github.com/atanunq/viu/releases/latest) then add the folder where the `viu` is stored to your environment variables.
`irctc-api` automatically installs `viu` binary based on your os and processor architecture, If we could not find your viu binary related to your processor and os, you are required to install `viu` through their standard installation.

Remeber to add the folder path and not the viu.exe file path in your environment variables.
Then provide `viu` binary path in params as

```json
{
"train_number": "11020",
"viu":"path/to/binary/viu | path/to/binary/viu.exe"
}
```


### Notes

- Currently this project is designed to accept only UPI Collect request as payment option and other payment modes are not supported as of now. When the payment request is initiated, The command line will display the payment request details such that you need to complete the payment from your UPI mobile App.

- We request to verify whether viu is working or not by giving the below command

```shell
viu example.jpeg -t
```

### Import

This Package exports a class named `IRCTC` which contains three functions.
Expand Down
8 changes: 7 additions & 1 deletion docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,15 @@ console.log(response);
- log
- Can be any one of the boolean values such as `true | false`
- Default value - `false`
- viu
- If you want your custom viu to be executed for captcha image, you can specify your path here
- Default - irctc-api will install viu binary package based on your os and processor architecture


The example input is as follows

```js
// some_book.mjs
{
"UPI": "9876543210@ybl",
"class": "2S",
Expand Down Expand Up @@ -152,7 +157,8 @@ The example input is as follows
}
],
"coach":"D1",
"log":true
"log":true,
"viu":"path/to/viu | path/to/viu.exe"
};
```

Expand Down
40 changes: 20 additions & 20 deletions lib/workings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { writeFileSync,readdirSync } from 'node:fs';
import {dirname,join} from "node:path";
import * as cheerio from 'cheerio';
import querystring from 'querystring';
import { execFile } from 'node:child_process';
import { execFileSync } from 'node:child_process';
import { URL,fileURLToPath } from 'node:url';
import {verify_booking_params, initialize_booking_variables, input, base64DecodeUnicode} from './utils.mjs';
import { psg_input_wait, sleep_for_login, sleep_for_availability_check} from "./time_work.mjs";
Expand Down Expand Up @@ -72,25 +72,8 @@ class IRCTC{
let imagePath = 'captcha.jpg';
this.log_data("Proceeding for Captcha Answering");
writeFileSync("./"+imagePath, this.captchaQuestion, 'base64');
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const path_l = join(__dirname, "..","bin");
const files = readdirSync(path_l);
let path_n = "";
if (files.length === 0) {
throw new Error("Platform not supported, Request you to manually download the viu binary file from rust standard installation page and place it inside this bin folder located in. "+path_l)
}
else{
path_n = files[0];
}
const binaryPath = join(path_l, path_n);
execFile(binaryPath, [imagePath,"-t"], (error, stdout, stderr) => {
console.log(`${stdout}\nEnter the Captcha Answer below in this terminal`);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
const stdout = execFileSync(this.binaryPath, [imagePath,"-t"]);
console.log(stdout+" \nPlease type the above text and press enter");
this.captcha_answer = await input('');
this.log_data("Received Captcha Answer Input");
await this.send_login();
Expand Down Expand Up @@ -708,6 +691,23 @@ class IRCTC{
}
async book(params){
this.log_file = new LOG(params.log);
if (params.viu && typeof params.viu === "string"){
this.binaryPath = params.viu;
}
else{
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const path_l = join(__dirname, "..","bin");
const files = readdirSync(path_l);
let path_n = "";
if (files.length === 0) {
throw new Error("Platform not supported, Request you to manually download the viu binary file from rust standard installation page and then after installing\nOption 1: Place the binary file inside this bin folder located in. "+path_l+"\nOption 2: Give viu binary path location in the params as 'viu':'path/to/viu | path/to/viu.exe'")
}
else{
path_n = files[0];
}
this.binaryPath = join(path_l, path_n);
}
this.logging = params.log;
this.params = params;
await verify_booking_params(this.params);
Expand Down
7 changes: 2 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "irctc-api",
"description": "An exclusive NodeJs only package built on top of IRCTC Website APIs to book train tickets, managing user profile faster and simpler from anywhere in the world",
"version": "2.0.12",
"version": "2.0.13",
"scripts": {
"postinstall": "node ./lib/postinstall.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit f4d6e63

Please sign in to comment.