项目作者: nikhilkumarsingh

项目描述 :
A python wrapper for Indian Railways Enquiry API!
高级语言: Python
项目地址: git://github.com/nikhilkumarsingh/pyinrail.git
创建时间: 2018-05-12T15:11:16Z
项目社区:https://github.com/nikhilkumarsingh/pyinrail

开源协议:MIT License

下载


PyPI
license

pyinrail

A python wrapper for Indian Railways Enquiry API!

  • Get trains between stations
  • Get seat availability
  • Get train fare
  • Get train schedule
  • Get train live running status
  • Get PNR status

…and much more!

Note: This is not an official package and using it for commercial purposes is not recommended.

Installation

To install pyinrail, simply,

  1. $ pip install pyinrail

You will also need to install tesseract-ocr. Find instructions to install tesseract-ocr here.

Usage

  • Importing pyinrail
  1. from pyinrail import pyinrail
  • Create RailwayEnquiry object

    1. enq = pyinrail.RailwayEnquiry(src='new delhi', dest='ahmedabad', date='12-05-2018')
  • Get trains between stations

  1. df = enq.get_trains_between_stations(as_df=True)
  2. print(df)
  1. trainName trainNumber fromStnCode toStnCode departureTime arrivalTime duration distance avlClasses
  2. 0 ADI SJ RAJDHANI 12958 NDLS ADI 19:55 09:40 13:45 935 [1A, 2A, 3A]
  3. 1 GUJRAT S KRANTI 12918 NZM ADI 13:55 06:10 16:15 1085 [2A, 3A, SL]
  4. 2 ASHRAM EXPRESS 12916 DLI ADI 15:20 07:40 16:20 934 [1A, 2A, 3A, SL]
  5. 3 ALA HAZRAT EXP 14311 DLI ADI 11:45 06:15 18:30 933 [2A, 3A, SL]
  6. 4 YOGA EXPRESS 19032 DSA ADI 21:26 17:10 19:44 963 [1A, 2A, 3A, SL]
  7. 5 DEE BDTS G RATH 12215 DEE ADI 09:20 01:10 15:50 951 [3A]
  • Get seat availability
  1. df = enq.get_seat_availability(12958, classc='2A', as_df=True)
  2. print(df)
  1. availablityDate availablityStatus availablityType currentBkgFlag reason reasonType waitListType
  2. 0 12-5-2018 TRAIN DEPARTED 8224 Y W 8224
  3. 1 13-5-2018 GNWL68/WL24 8224 N S 9
  4. 2 14-5-2018 GNWL41/WL8 8224 N S 9
  5. 3 15-5-2018 GNWL25/WL6 8224 N S 9
  6. 4 16-5-2018 GNWL33/WL14 8224 N S 9
  7. 5 17-5-2018 GNWL20/WL9 8224 N S 9
  • Get train schedule
  1. df = enq.get_train_schedule(12958, as_df=True)
  2. print(df)
  1. stationCode stationName departureTime arrivalTime routeNumber haltTime distance dayCount stnSerialNumber
  2. 0 NDLS NEW DELHI 19:55 -- 1 -- 0 1 1
  3. 1 DEC DELHI CANTT 20:25 20:23 1 02:00 16 1 2
  4. 2 GGN GURGAON 20:43 20:41 1 02:00 32 1 3
  5. 3 JP JAIPUR 00:30 00:20 1 10:00 309 2 4
  6. 4 AII AJMER JN 02:29 02:25 1 04:00 443 2 5
  7. 5 FA FALNA 04:53 04:52 1 01:00 650 2 6
  8. 6 ABR ABU ROAD 06:05 06:01 1 04:00 748 2 7
  9. 7 PNU PALANPUR JN 07:12 07:10 1 02:00 801 2 8
  10. 8 MSH MAHESANA JN 08:05 08:03 1 02:00 866 2 9
  11. 9 SBIB SABARMATI BG 09:02 09:00 1 02:00 929 2 10
  12. 10 ADI AHMEDABAD JN -- 09:40 1 -- 935 2 11
  • Get train fare
  1. fare_data = enq.get_train_fare(12958, classc='2A')
  2. print(fare_data)
  1. {'baseFare': 1841,
  2. 'cateringCharge': 225,
  3. 'dynamicFare': 921,
  4. 'fuelAmount': 0.0,
  5. 'goodsServiceTax': 143.0,
  6. 'otherCharge': 0,
  7. 'reservationCharge': 50,
  8. 'superfastCharge': 45,
  9. 'tatkalFare': 0,
  10. 'totalCollectibleAmount': 3225.0,
  11. 'totalConcession': 0,
  12. 'totalFare': 3225,
  13. 'travelInsuranceCharge': 0.0,
  14. 'travelInsuranceServiceTax': 0.0,
  15. 'wpServiceCharge': 0.0,
  16. 'wpServiceTax': 0.0}
  • Get train’s live running status
  1. train_detail, instances, detailed_instances = enq.get_train_status(12958, as_df=True)
  2. print(train_detail)
  3. print(instances)
  4. print(detailed_instances[0])
  1. {'dayCnt': '1',
  2. 'from': 'NDLS',
  3. 'runsOn': '1111111',
  4. 'schArrTime': '09:40',
  5. 'schDepTime': '19:55',
  6. 'to': 'ADI',
  7. 'trainName': 'ADI SJ RAJDHANI',
  8. 'trainNo': '12958'}
  9. startDate departed curStn terminated lastUpdated totalLateMins
  10. 0 12 May 2018 True RE False 12 May 2018 21:43 6
  11. 1 11 May 2018 True ADI True 12 May 2018 9:27 -14
  12. stnCode arr schArrTime actArr delayArr dep schDepTime actDep delayDep dayCnt schDayCnt distance
  13. 0 NDLS False 00:00 00:00 0 True 19:55 19:55 0 0 0 0
  14. 1 DEC True 20:23 20:27 4 True 20:25 20:29 4 0 0 15
  15. 2 GGN True 20:41 20:47 6 True 20:43 20:49 6 0 0 32
  16. 3 RE True 21:30 21:41 11 True 21:30 21:41 11 0 0 83
  17. 4 JP False 00:20 00:20 0 False 00:30 00:30 0 1 1 308
  18. 5 AII False 02:25 02:25 0 False 02:29 02:29 0 1 1 442
  19. 6 FA False 04:52 04:52 0 False 04:53 04:53 0 1 1 649
  20. 7 ABR False 06:01 06:01 0 False 06:05 06:05 0 1 1 747
  21. 8 PNU False 07:10 07:10 0 False 07:12 07:12 0 1 1 800
  22. 9 MSH False 08:03 08:03 0 False 08:05 08:05 0 1 1 865
  23. 10 SBIB False 09:00 09:00 0 False 09:02 09:02 0 1 1 927
  24. 11 ADI False 09:40 09:40 0 False 00:00 00:00 0 1 1 934

TODOs

  • A command line client
  • A GUI interface

Want to contribute?

  • Clone the repository

    1. $ git clone http://github.com/nikhilkumarsingh/pyinrail
  • Install dependencies

    1. $ pip install -r requirements.txt
  • To test local version of pyinrail:

    1. $ pip install -U .

    OR :

    1. $ pip install -e <project dir.> .