Indian railway API python

Pnr Status API In Python – Indian railways API python

Python

Indian railways API python :- PNR Status API In Python me aaj ham PNR Status check karne wale hai wo bhi python code ki help se or ham sara data fetch karenge like pnr number and train name , current status , booking status etc |

PNR Status API In Python

Indian Railways Api Ki Help or Python Pnr status api Code ki help Se Pnr status and etc data fetch karne wale hai | Me aapko ab step by step batane wala hu jis se hame Learn karne me aashani ho jayegi or Friends agar koi python Django se website bhi banane wale hai to aap yehi code waha par apply kar sakte hai ye python pnr status api code waha par bhi work karega |

Indian railway API python
Pnr Status API In Python – Indian railway API python

Step 1: Download Pycharm And Python Request And Json Module

Dosto Python PNR Status Data Fetch karne ke liye Sabse Pahle Hame kuch python module or pycharm ko download karna hoga | Download karne ka link niche diya gya hai aap link par click karke download kar sakte hai |

Download :- Pycharm

Ab Ham Python Ka 2 Module Hai Jiska Name Hai Requests , Json Module Usko Ham ab Download Karte hai wo bhi CMD ki help se | Sabse Pahle Aapko Python ki Directory me jana hai |

Goto This Directory :-C:\Users\PC_Name\AppData\Local\Programs\Python\Python37-32\Scripts

Or Aap Is Directory Me Jane ke Bad Aapko SHIFT + LEFT CLICK press karna hoga | Uske Bad Aapko Open command window here par click karna hoga |

Open command window par click karne ke bad aapko command window open ho jayegi | Open Hone Ke bad aapko RESQUESTS Module download karna hai uske liye aapko ye type karna hoga |

pip install requests

Ye Likhe ne bad aapko ENTER press karna hoga fir requests module aapne aap downlaod ho jayega |

pip install json

Json module ko bhi aapko wese hi download karna hai jese hamne requests module ko download kiya hai | Ye Dono Module Download Karne ke bad aapko step 2 me jana hai |

Step 2: Need Indian Railways Api

Friends Ab Hame Indian Railways Api ki jarurat hai uske liye ham is website jane wale hai us website ka name hai IndianRailapi.com

Indian Railway api :- IndianRainlapi.com

Indian Rail Api Website jane ke bad sabse pahle ragistration karna hoga or fir aapko Login Karna hoga ye website free of cost hai |

Indian Rail Api Website Login Karne Ke bad appko ek Aisa Interface Open Hua Hoga | Open Hone ke bad aapko API KEY kar par click karna hoga jeisa ki upper diye gye image me dikhaya gya hai |

Yaha Par Aapko Api key ko copy kar lena hoga or fir ham python ke code me ye api add karne wale hai |

Step 3: Indian Railways Api Python Code

Ab Ham Python Code ko Write karne wale hai or fir Pnr status check karne wale hai |

Sabse Pahle Aapko Requests module and json module ko import karna hai |

import requests ,json

pnr_no = "write your pnr number"


a = "https://indianrailapi.com/api/v2/PNRCheck/apikey/write your api key /PNRNumber/"+ pnr_no + "/"

Aap Uper Dekh Sakte Hai Hamne Code ko Jaha par pnr_no hai waha par aapko aapna pnr number dalna hai or jaha api key hai waha par aapko aapni api key dalna hai | Keval aapko ye hi change karne hai uske bad aapko niche diye pure code ko istemal kar sakte hai |

Python Pnr Status Code

Niche Diye Gye Code Me Keval Pnr Nubmer or Api Key Change Karna Hoga aapko uske bad aap ye code ka istemal kar sakte hai|

import requests ,json

pnr_no = "4465877280"


a = "https://indianrailapi.com/api/v2/PNRCheck/apikey/375b8caa6a27e3d1b9922c851245c93f/PNRNumber/"+ pnr_no + "/"

dk = requests.get(a)
result = dk.json()

if result["ResponseCode"] == '200': 

	pnr_number = result['PnrNumber']
	train_name = result["TrainNumber"] 
	Journey_class = result["JourneyClass"] 
	Chat_Prepared = result["ChatPrepared"] 
	from_station = result["From"] 
	to_station = result["To"]
	dateof_journey = result["JourneyDate"]
	passengers_list = result["Passangers"] 

	print(f"PnrNumber {pnr_number}\nTrain Name {train_name}\nJourney Class {Journey_class}\nChart Preadared {Chat_Prepared}\nFrom Station {from_station} To {to_station}\nJourney Date {dateof_journey}")

	for passenger in passengers_list: 

		passenger_num = passenger["Passenger"]

		current_status = passenger["CurrentStatus"] 

		booking_status = passenger["BookingStatus"] 

		print(" passenger number : " + str(passenger_num) 
			 + "\n current status : " + str(current_status) 
			+ "\n booking_status : " + str(booking_status)) 
  
else:	
	print("Wrong Pnr Number")	


Output :

Also Read This Post :

Indian railways API python

Dosto mujhe ummed hai ki aap Indian railways API python hindi ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre or ha agar aap video bhi dekhna chahte hai to aap mere channel ko bhi subscribe kar sakte hai. channel ka link aapko home page par mil jayega |

Leave a Reply

Your email address will not be published. Required fields are marked *