-
Notifications
You must be signed in to change notification settings - Fork 0
/
spot_ur_train.py
executable file
·40 lines (37 loc) · 1.28 KB
/
spot_ur_train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
from bs4 import BeautifulSoup
chakra = True
trial = 5
# train_no = 22104
train_no = int(input("Enter the train no."))
days = int(
input("enter the starting day number..('0' for today, '1' for yesterday, 2 for day before yesterday and so "
"on...)")) * -1
# days = -1
while chakra and trial >= 0:
try:
sc = requests.get("http://spoturtrain.com/status.php?tno=" + str(train_no) + "&date=+" + str(days))
soup = BeautifulSoup(sc.text, 'lxml')
tr = soup.find_all("tr")
for td in tr[1].find_all("font"):
print(td.getText().strip("\t").strip("\n") + "\n")
print("-----------------------------------------------------------------------------------\n\n")
print("Station -> ETA")
print("--------------")
for i in range(3, len(tr)):
rows = tr[i]
str = ""
flag = True
for td in rows.find_all("td"):
str = str + td.getText().strip('\n') + " "
if flag:
str = str + "-> "
flag = False
print(str)
chakra = False
trial -= 1
except:
trial -= 1
print("Kuch toh locha hai... reattempting")
if chakra:
print("Successfully Failed... Please try again")