Confirmtkt

Remember:

  • Replace placeholders like your_irctc_user_id and your_phone_number with actual values.
  • You'll need to have the MultiFeatures package installed to run these examples.
  • These examples are asynchronous and need to be run within an async function using await.
  • Install the package using pip install -U MultiFeatures.

Usage

from MultiFeatures.IndianRailway import confirmtkt
 
confirmtkt = confirmtkt.Confirmtkt()

Methods

live_train_status(train_no: str, doj: str, locale: str = 'en')

Gets the live status of a train from the ConfirmTkt API.

Parameters:

  • train_no (str): The train number.
  • doj (str): The date of journey in the format 'dd-mm-yyyy'.
  • locale (str, optional): The locale for the response. Defaults to 'en'.

Raises:

  • NotAValidTrainNumber: If the provided train number is not valid.
  • InternetUnreachable: If there is an issue connecting to the internet.
  • HTTPErr: If the response status code is not 200.

Returns:

  • dict: The JSON response containing live train status information.

Example:

status = await confirmtkt.live_train_status("12625", "10-11-2023")
print(status)

available_trains(src: str, dest: str, doj: str, quota: str = 'GN')

Fetch available trains between two stations.

Parameters:

  • src (str): Source station code.
  • dest (str): Destination station code.
  • doj (str): Date of journey in the format 'dd-mm-yyyy'.
  • quota (str): Quota for the availability check. Default is "GN".

Returns:

  • dict: Available trains between the specified stations.
  • None: If no trains are available (as Str).

Raises:

  • InternetUnreachable: If a connection error occurs during the API request.
  • HTTPErr: If the response status code is not 200.

Example:

trains = await confirmtkt.available_trains("NDLS", "MAS", "15-12-2023")
print(trains)

is_irctc_user_id_valid(user_id: str)

Checks if the provided IRCTC user ID is valid.

Parameters:

  • user_id (str): The IRCTC user ID to check.

Returns:

  • bool: True if the user ID is valid, False otherwise.

Example:

is_valid = await confirmtkt.is_irctc_user_id_valid("your_irctc_user_id")
print(is_valid)

reset_irctc_account_password(user_id, contact_info, is_email=False)

Reset the password of an IRCTC account. New password will be sent to the provided contact info.

Parameters:

  • user_id (str): The IRCTC user ID.
  • contact_info (str): The phone number or email address associated with the IRCTC account.
  • is_email (bool, optional): Whether the provided contact info is an email address. Defaults to False.

Returns:

  • dict: The JSON response from the API.

Raises:

  • InternetUnreachable: If a connection error occurs during the API request.
  • HTTPErr: If the response status code is not 200.

Example:

response = await confirmtkt.reset_irctc_account_password("your_irctc_user_id", "your_phone_number")
print(response)

pnr_info(pnr: int)

Gets the PNR status from the ConfirmTkt API.

Parameters:

  • pnr (int): The PNR number.

Returns:

  • dict: The JSON response containing PNR status information.

Raises:

  • ValueError: If PNR is not a 10-digit integer.

Example:

pnr_status = await confirmtkt.pnr_info(1234567890)
print(pnr_status)

train_search(train: str)

Search for a train by its number.

Parameters:

  • train (str): The train number.

Returns:

  • dict: The JSON response containing train information.

Example:

train_info = await confirmtkt.train_search("12625")
print(train_info)

train_schedule(train_no: int, date: str, locale: str = 'en')

Gets the schedule of a train from the ConfirmTkt API.

Parameters:

  • train_no (int): The train number.
  • date (str): The date for which the schedule is required.
  • locale (str, optional): The locale for the response. Defaults to 'en'.

Returns:

  • dict: The JSON response containing train schedule information.

Example:

schedule = await confirmtkt.train_schedule(12625, "10-11-2023")
print(schedule)

get_stations_list()

Get the list of stations from the ConfirmTkt API.

Returns:

  • dict: The JSON response containing the list of stations.

Example:

stations = await confirmtkt.get_stations_list()
print(stations)

send_otp(phone_number: str)

Send OTP to the provided phone number.

Parameters:

  • phone_number (str): The phone number without +91 to which the OTP will be sent.

Raises:

  • ValueError: If the phone number is invalid.

Example:

response = await confirmtkt.send_otp("9876543210")
print(response)

verify_otp(phone_number: str, otp: str)

Verify the OTP received on the provided phone number.

Parameters:

  • phone_number (str): The phone number without +91.
  • otp (str): The OTP received.

Raises:

  • ValueError: If the phone number is invalid.
  • Exception: If OTP verification fails.

Example:

response = await confirmtkt.verify_otp("9876543210", "123456")
print(response)

smart_switch(from_station: str, to_station: str, date: str, train_type: Optional[str] = None, preferred_class: Optional[str] = None, token: Optional[str] = None)

Gets smart switch options for train travel between two stations.

Parameters:

  • from_station (str): The source station code.
  • to_station (str): The destination station code.
  • date (str): The date of journey in the format 'dd-mm-yyyy'.
  • train_type (str, optional): The type of train (e.g., "Shatabdi", "Rajdhani"). Defaults to None.
  • preferred_class (str, optional): The preferred travel class (e.g., "SL", "3A"). Defaults to None.
  • token (str, optional): The authentication token. If not provided, the token from the instance will be used. Defaults to None.

Returns:

  • dict: The JSON response containing smart switch options.

Raises:

  • InternetUnreachable: If there's an issue connecting to the internet.
  • Exception: If the API request fails or returns an error.

Example:

options = await confirmtkt.smart_switch("NDLS", "MAS", "15-12-2023", train_type="Shatabdi", preferred_class="3A")
print(options)