Confirmtkt
Remember:
- Replace placeholders like
your_irctc_user_id
andyour_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 usingawait
. - Install the package using
pip install -U MultiFeatures
.
Usage
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:
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:
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:
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:
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:
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_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:
get_stations_list()
Get the list of stations from the ConfirmTkt API.
Returns:
dict
: The JSON response containing the list of stations.
Example:
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:
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:
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: