├── train1.ico ├── process.gif ├── README.md ├── Initialize.py ├── LICENSE ├── .gitignore └── IRCTC_Tatkal_Booking.py /train1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-vishal/IRCTC-tatkal_booking/HEAD/train1.ico -------------------------------------------------------------------------------- /process.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-vishal/IRCTC-tatkal_booking/HEAD/process.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IRCTC-tatkal_booking 2 | For fast railway tatkal ticket booking, automated by selenium. 3 | 4 | ![image](https://raw.githubusercontent.com/the-vishal/IRCTC-tatkal_booking/master/process.gif) 5 | 6 | # Steps 7 | 1.Run Initialize file and enter your user ID and Password, This is only one time process on each machine. 8 | 9 | 2.Edit your details: from, to_station, date, train_number, gender, birth preference, and passenger details in manner shown in file. 10 | 11 | 3. Enter payment details and captcha by your own. 12 | -------------------------------------------------------------------------------- /Initialize.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import keyring 3 | import getpass 4 | 5 | 6 | #sql file for username only 7 | conn = sqlite3.connect('Booking_Details.db') 8 | 9 | 10 | conn.execute('''CREATE TABLE IF NOT EXISTS user 11 | (NAME TEXT NOT NULL);''') 12 | 13 | 14 | 15 | print("It is only one time initialization to secure you Login credentials.\n") 16 | 17 | user_name = input('Enter your USERNAME : ') 18 | password = getpass.getpass('Enter you PASSWORD (Hidden) : ') 19 | 20 | 21 | conn.execute("INSERT INTO user (NAME) \ 22 | VALUES ('{}')".format(user_name)) 23 | 24 | conn.commit() 25 | print ("User created successfully") 26 | conn.close() 27 | #password is safe with windows vault 28 | 29 | 30 | #setting to windows vault 31 | keyring.set_password('irctc',user_name,password) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 V!shal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /IRCTC_Tatkal_Booking.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.keys import Keys 3 | import keyboard 4 | import time 5 | import sqlite3 6 | import keyring 7 | from win10toast import ToastNotifier 8 | 9 | 10 | 11 | #*********************************************************** 12 | 13 | #journey details 14 | 15 | from_station = 'AMBALA CANT JN - UMB' 16 | to_station ='VARANASI JN - BSB' 17 | date = '26-05-2018' 18 | train_no = '13152' 19 | class_ = '3A' 20 | quota = 'GN' 21 | phone_no = '9115XXXXXX' 22 | 23 | 24 | 25 | #passengers details [Name, age, gender ,birth_choice] 26 | passenger_details = [ 27 | ['VISHAL KUMAR','20','M','LB'], 28 | ['VIKAS KUMAR','24','M','LB'] 29 | ] 30 | 31 | 32 | 33 | 34 | #*********************************************************** 35 | 36 | 37 | def captcha_msg(): 38 | toaster = ToastNotifier() 39 | toaster.show_toast(title='IRCTC',msg='Enter CAPTCHA value', icon_path='train1.ico') 40 | 41 | 42 | 43 | #*********************************************************** 44 | #login details in keyring module 45 | conn = sqlite3.connect('Booking_Details.db') 46 | cursor = conn.cursor() 47 | 48 | cursor.execute('''SELECT NAME FROM user''') 49 | user = cursor.fetchall()[0][0] 50 | conn.close() 51 | 52 | pasw = keyring.get_password('irctc', user) 53 | 54 | 55 | #gender xpaths 56 | gender = { 57 | 'F':'//*[@id="addPassengerForm:psdetail:1:psgnGender"]/option[2]', 58 | 'M':'//*[@id="addPassengerForm:psdetail:1:psgnGender"]/option[3]', 59 | 'T':'//*[@id="addPassengerForm:psdetail:1:psgnGender"]/option[4]'} 60 | 61 | 62 | #births xpaths 63 | birth_pref = { 64 | 'LB':'//*[@id="addPassengerForm:psdetail:0:berthChoice"]/option[2]', 65 | 'MB':'//*[@id="addPassengerForm:psdetail:0:berthChoice"]/option[3]', 66 | 'UP':'//*[@id="addPassengerForm:psdetail:0:berthChoice"]/option[4]', 67 | 'SL':'//*[@id="addPassengerForm:psdetail:0:berthChoice"]/option[5]', 68 | 'SU':'//*[@id="addPassengerForm:psdetail:0:berthChoice"]/option[6]'} 69 | 70 | 71 | #initializing driver 72 | browser = webdriver.Chrome() 73 | url ="https://www.irctc.co.in/eticketing/loginHome.jsf" 74 | 75 | #opening url 76 | browser.get(url) 77 | 78 | #filling login section 79 | username = browser.find_element_by_name("j_username") 80 | username.send_keys(user) 81 | 82 | password = browser.find_element_by_name("j_password") 83 | password.send_keys(pasw) 84 | 85 | #presses tab key to goto captcha entry 86 | password.send_keys(Keys.TAB) 87 | 88 | captcha_msg() 89 | 90 | #for captcha entering, press enter after entering captcha or wait for click 91 | while True: 92 | if keyboard.is_pressed('enter'): 93 | browser.find_element_by_xpath('//*[@id="loginbutton"]').click() 94 | break 95 | 96 | elif browser.title=='E-Ticketing': 97 | break 98 | # login complete 99 | 100 | 101 | 102 | 103 | #Filling the journey Planner 104 | from_ = browser.find_element_by_name("jpform:fromStation") 105 | from_.send_keys(from_station) 106 | 107 | 108 | to_ = browser.find_element_by_name("jpform:toStation") 109 | to_.send_keys(to_station) 110 | 111 | 112 | date_ = browser.find_element_by_name("jpform:journeyDateInputDate") 113 | date_.send_keys(date) 114 | 115 | 116 | 117 | #plan journey form submit 118 | browser.find_element_by_name("jpform:jpsubmit").click() 119 | 120 | #Check quota radio button to Tatkal 121 | browser.find_element_by_xpath('//*[@id="qcbd"]/table/tbody/tr/td[6]/input').click() 122 | 123 | #select class 124 | cls= [] 125 | for i in browser.find_elements_by_link_text(class_): 126 | cls.append( i.get_attribute("id")) 127 | 128 | class_select =None 129 | for result in cls: 130 | if train_no in result.split('-'): 131 | class_select = '//*[@id="'+result+'"]' 132 | 133 | 134 | browser.find_element_by_xpath(class_select).click() 135 | 136 | 137 | #Book now 138 | #**************** Boht time lga is section ko krne me :) *********************** 139 | time.sleep(1) #wait for book now link to be generated 140 | # xpath="(//a[contains(text(),'Book Now')])[2]" 141 | # browser.find_element_by_xpath(xpath).click() 142 | browser.find_element_by_link_text('Book Now').click() 143 | 144 | 145 | #pehle ye kiya tha, click khud karo : 146 | # while True: 147 | # if browser.title == 'Book Ticket - Passengers Information': 148 | # break 149 | 150 | 151 | 152 | info_index=0 #name,age,gender,birth in passenger_details list 153 | 154 | #fill name of all the passengers 155 | for passg in browser.find_elements_by_xpath("//*[@class='input-style1 psgn-name']"): 156 | passg.send_keys(passenger_details[info_index][0]) 157 | info_index+=1 158 | if info_index == len(passenger_details): 159 | info_index=0 160 | break 161 | 162 | 163 | #fill age of all the passengers 164 | for pass_age in browser.find_elements_by_xpath('//*[@class="input-style1 psgn-age only-numeric"]'): 165 | pass_age.send_keys(passenger_details[info_index][1]) 166 | info_index += 1 167 | if info_index == len(passenger_details): 168 | info_index = 0 169 | break 170 | 171 | 172 | #fill gender of all the passengers 173 | for pass_gender in browser.find_elements_by_xpath('//*[@class="input-style1 psgn-gender"]'): 174 | pass_gender.send_keys(passenger_details[info_index][2]) 175 | info_index += 1 176 | if info_index == len(passenger_details): 177 | info_index = 0 178 | break 179 | 180 | 181 | #fill birth choice of all the passengers 182 | for pass_birth in browser.find_elements_by_xpath('//*[@class ="input-style1 psgn-berth-choice"]'): 183 | pass_birth.send_keys(passenger_details[info_index][3]) 184 | info_index += 1 185 | if info_index == len(passenger_details): 186 | info_index = 0 187 | break 188 | 189 | 190 | 191 | #fill phone number on which ticket message is sent 192 | ticket_phone_no = browser.find_element_by_xpath('//*[@class="textfield01 mobile-number only-numeric"]') 193 | ticket_phone_no.clear() 194 | ticket_phone_no.send_keys(phone_no) 195 | 196 | 197 | captcha_msg() 198 | 199 | 200 | #take to the captcha input if input captcha else in click captcha pass 201 | try: 202 | captcha = browser.find_element_by_xpath('//*[@id="nlpAnswer"]') 203 | captcha.click() 204 | except: 205 | pass 206 | 207 | 208 | 209 | #ENTER CAPTCHA AND HIT ENTER or wait for a click 210 | while True: 211 | if keyboard.is_pressed('enter'): 212 | break 213 | 214 | elif browser.title == 'Book Ticket - Journey Summary': 215 | break 216 | 217 | 218 | #Payment Section 219 | browser.find_element_by_id('AGGREGATOR').click() 220 | browser.find_element_by_name('AGGREGATOR').click() 221 | browser.find_element_by_xpath('//*[@id="validate"]').click() 222 | --------------------------------------------------------------------------------