|
| 1 | +from selenium import webdriver |
| 2 | +from PIL import Image |
| 3 | +import pytesseract |
| 4 | +import io |
| 5 | +import numpy as np |
| 6 | +import cv2 as cv |
| 7 | +import time |
| 8 | +import tkinter |
| 9 | +from tkinter import ttk |
| 10 | +from webdriver_manager.chrome import ChromeDriverManager |
| 11 | + |
| 12 | + |
| 13 | +def click(): |
| 14 | + global inputpnrnumber |
| 15 | + inputpnrnumber = str(name.get()) |
| 16 | + if (inputpnrnumber.isnumeric()) and ( len(inputpnrnumber) == 10 ) : |
| 17 | + window.destroy() |
| 18 | + |
| 19 | + |
| 20 | +def GUI() : |
| 21 | + window.title("PNR STATUS") |
| 22 | + lbl = ttk.Label(window, text = " ") |
| 23 | + lbl.grid(column = 0, row = 0) |
| 24 | + lbl = ttk.Label(window, text = " Enter PNR Number: ") |
| 25 | + lbl.grid(column = 0, row = 1) |
| 26 | + nameEntered = ttk.Entry(window, width = 12, textvariable = name) |
| 27 | + nameEntered.grid(column = 1, row = 1) |
| 28 | + lbl = ttk.Label(window, text = " ") |
| 29 | + lbl.grid(column = 2, row = 1) |
| 30 | + lbl = ttk.Label(window, text = " ") |
| 31 | + lbl.grid(column = 1, row = 2) |
| 32 | + button = ttk.Button(window, text = "Submit", command = click) |
| 33 | + button.grid(column = 1, row = 3) |
| 34 | + lbl = ttk.Label(window, text = " ") |
| 35 | + lbl.grid(column = 1, row = 4) |
| 36 | + window.mainloop() |
| 37 | + |
| 38 | +window = tkinter.Tk() |
| 39 | +name = tkinter.StringVar() |
| 40 | +url="http://www.indianrail.gov.in/enquiry/PNR/PnrEnquiry.html?locale=en" |
| 41 | + |
| 42 | +GUI() |
| 43 | + |
| 44 | +#google = input(r"Enter google executable path"); |
| 45 | +tess = input(r"Enter tesseract path: "); |
| 46 | + |
| 47 | +browser = webdriver.Chrome( |
| 48 | + executable_path=ChromeDriverManager().install()) |
| 49 | +browser.get(url) |
| 50 | +pnrnumber = browser.find_element_by_id('inputPnrNo') |
| 51 | +pnrnumber.send_keys(inputpnrnumber) |
| 52 | +close = browser.find_element_by_id('corover-close-btn') |
| 53 | +close.click() |
| 54 | +submit = browser.find_element_by_id('modal1') |
| 55 | +submit.click() |
| 56 | +captchascreenshot = browser.find_element_by_xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div/div/div/div[2]/div[2]/div/div[2]") |
| 57 | +time.sleep(2) |
| 58 | +screenshotimagebinary = captchascreenshot.screenshot_as_png |
| 59 | +img_array = np.array(bytearray(screenshotimagebinary), dtype=np.uint8) |
| 60 | +img = cv.imdecode(img_array, 0) |
| 61 | +(thresh, blackAndWhiteImage) = cv.threshold(img, 120,255, cv.THRESH_BINARY) |
| 62 | +pytesseract.pytesseract.tesseract_cmd = tess |
| 63 | +prob = pytesseract.image_to_string(blackAndWhiteImage) |
| 64 | +prob = prob.replace('=', ' ') |
| 65 | +prob = prob.replace('?', ' ') |
| 66 | +add = prob.find('+') |
| 67 | +subtract = prob.find('-') |
| 68 | +if add != -1 : |
| 69 | + k=1 |
| 70 | + prob = prob.replace('+', ' ') |
| 71 | +if subtract != -1 : |
| 72 | + k=2 |
| 73 | + prob = prob.replace('-', ' ') |
| 74 | +j = 0 |
| 75 | +while j < len(prob): |
| 76 | + q = prob[j] |
| 77 | + if not(q.isdigit()): |
| 78 | + prob = prob.replace(prob[j], ' ') |
| 79 | + j+=1 |
| 80 | + |
| 81 | +i = prob.split(" ", 1) |
| 82 | +print(prob) |
| 83 | +num1=int(i[0]) |
| 84 | +num2=int(i[1]) |
| 85 | +if k == 1 : |
| 86 | + sol=num1+num2 |
| 87 | +if k == 2 : |
| 88 | + sol=num1-num2 |
| 89 | +print(str(sol)) |
| 90 | +ans = browser.find_element_by_id('inputCaptcha') |
| 91 | +ans.send_keys(str(sol)) |
| 92 | +time.sleep(1) |
| 93 | +submit1 = browser.find_element_by_id('submitPnrNo') |
| 94 | +submit1.click() |
| 95 | +time.sleep(3) |
| 96 | + |
| 97 | +screenshot = browser.find_element_by_xpath("//html/body/div[2]/div[2]/div[2]") |
| 98 | +screenshotimagebin = screenshot.screenshot_as_png |
| 99 | +imgarray = np.array(bytearray(screenshotimagebin), dtype=np.uint8) |
| 100 | +img1 = cv.imdecode(imgarray, cv.IMREAD_COLOR) |
| 101 | +cv.imshow("PNR STATUS",img1) |
| 102 | +cv.imwrite("PNRSTATUS.png", img1) |
| 103 | + |
0 commit comments