Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cfdf7fd

Browse files
Merge pull request avinashkranjan#1142 from Amit366/new
Train Pnr Status
2 parents dc641a9 + 3d7e5f8 commit cfdf7fd

File tree

4 files changed

+159
-2
lines changed

4 files changed

+159
-2
lines changed

‎GST Calculator/Readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
## DEMO
3232
![Screenshot (241)](https://user-images.githubusercontent.com/60662775/116357999-c86af180-a81a-11eb-91b2-fe1bca70872c.png)
3333

34+
- re
35+
- requests
36+
- urllib.request
37+
3438
## Author
3539

36-
Amit Kumar Mishra
37-
40+
[Amit Kumar Mishra](https://github.com/Amit366)

‎Train_pnr_status/Readme.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# <b>Train PNR Status</b>
2+
3+
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
4+
5+
## Train PNR Status Functionalities : 🚀
6+
7+
- Enter the tesseract path
8+
- After entering a GUI will pop up in which enter the PNR number and click on submit
9+
- The script will fill the perform web scrapping and display the PNR status
10+
11+
## Setup:
12+
13+
- Google should be updated to latest version
14+
15+
## Train PNR Status Instructions: 👨🏻‍💻
16+
17+
### Step 1:
18+
19+
Open Termnial 💻
20+
21+
### Step 2:
22+
23+
Locate to the directory where python file is located 📂
24+
25+
### Step 3:
26+
27+
Run the command: python script.py/python3 script.py 🧐
28+
29+
### Step 4:
30+
31+
Sit back and Relax. Let the Script do the Job. ☕
32+
33+
## DEMO
34+
35+
![Screenshot (264)](https://user-images.githubusercontent.com/60662775/120154793-d6db6d00-c20d-11eb-84bd-52c1d1a5a4c2.png)
36+
37+
After clicking on submit it goes to official IRCTC website and draws the PNR status.
38+
39+
40+
## Author
41+
42+
[Amit Kumar Mishra](https://github.com/Amit366)
43+

‎Train_pnr_status/requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
selenium
2+
PIL
3+
pytesseract
4+
io
5+
numpy
6+
time
7+
cv2
8+
tkinter

‎Train_pnr_status/script.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /