Skip to content

Commit b102d36

Browse files
authored
Merge pull request #587 from nikhilisaac/nikhil-patch
added pnr_status_checker
2 parents fe2c33a + db6893a commit b102d36

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

pnr_status_checker/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This is a python script to check the current PNR status in Indian Railways using INDRAIL API
2+
3+
# running the script
4+
install the required modules
5+
6+
open the terminal in same directory and run
7+
8+
```
9+
pip install -r requirements.txt
10+
```
11+
12+
after that run the script and enter the pnr no. when prompted to get the details
13+
14+
15+
# Note
16+
if the script doesn't work pls check if you have entered your API key which can be generated by
17+
18+
visiting the website
19+
# https://indianrailapi.com/
20+
21+
create your account and generate your api key and replace it in the script
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import requests
2+
api_key = "<your API KEY>"
3+
base_url = "https://api.railwayapi.com/v2/pnr-status/pnr/"
4+
pnr_number = str(input("enter the PNR number"))
5+
# you'll get traceback error if you don't enter your api key
6+
complete_url = base_url + pnr_number + "/apikey/" + api_key + "/"
7+
response_ob = requests.get(complete_url)
8+
result = response_ob.json()
9+
if result["response_code"] == 200:
10+
train_name = result["train"]["name"]
11+
train_number = result["train"]["number"]
12+
from_station = result["from_station"]["name"]
13+
to_station = result["to_station"]["name"]
14+
boarding_point = result["boarding_point"]["name"]
15+
reservation_unto = result["reservation_unto"]["name"]
16+
pnr_num = result["pnr"]
17+
date_of_journey = result["doj"]
18+
total_passengers = result["total_passengers"]
19+
passengers_list = result["passengers"]
20+
chart_prepared = result["chart_prepared"]
21+
print(" train name : " + str(train_name)
22+
+ "\n train number : " + str(train_number)
23+
+ "\n from station : " + str(from_station)
24+
+ "\n to station : " + str(to_station)
25+
+ "\n boarding point : " + str(boarding_point)
26+
+ "\n reservation unto : " + str(reservation_unto)
27+
+ "\n pnr number : " + str(pnr_num)
28+
+ "\n date of journey : " + str(date_of_journey)
29+
+ "\n total no. of passengers: " + str(total_passengers)
30+
+ "\n chart prepared : " + str(chart_prepared))
31+
# for multiple passengers against same PNR
32+
for passenger in passengers_list:
33+
passenger_num = passenger["no"]
34+
current_status = passenger["current_status"]
35+
booking_status = passenger["booking_status"]
36+
# print following values
37+
print(" passenger number : " + str(passenger_num)
38+
+ "\n current status : " + str(current_status)
39+
+ "\n booking_status : " + str(booking_status))
40+
else:
41+
print("Record Not Found")

pnr_status_checker/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests~=2.26.0

0 commit comments

Comments
 (0)