-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathControl.py
More file actions
48 lines (44 loc) · 2.26 KB
/
Control.py
File metadata and controls
48 lines (44 loc) · 2.26 KB
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
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""
@author: Birol Emekli
"""
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException,TimeoutException,UnexpectedAlertPresentException
import sys
import Mail
class Control:
def __init__(self,driver,time,email):
self.driver=driver
self.time=time
self.email=email
def sayfaKontrol(self):
try:
elem = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//*[@id='mainTabView:gidisSeferTablosu:1:j_idt109:0:somVagonTipiGidis1_label']")))
if elem != "":
for row in range(1, 15):
try:
if self.time == self.driver.find_element_by_xpath('/html/body/div[3]/div[2]/div/div/div/div/form/div[1]/div/div[1]/div/div/div/div[1]/div/div/div/table/tbody/tr[{0}]/td[1]/span'.format(row)).text:
message=self.driver.find_element_by_xpath('//*[@id="mainTabView:gidisSeferTablosu:{0}:j_idt109:0:somVagonTipiGidis1_label"]'.format(row - 1)).text
if message[22] != '0':
Mail.Mail(self.email, message).sendMail()
print(message)
return "successful"
else:
print("Aradığınız seferde boş yer yok...")
self.driver.quit()
return
except:
print ("Saatinizde hata var...")
self.driver.quit()
sys.exit()
else:
print("Aradığınız seferde boş yer yoktur...")
except (TimeoutException,NoSuchElementException) as ex:
print ("TCDD sitesi yüklemede bir hata meydana geldi... Tekrar deneniyor...")
self.driver.quit()
except UnexpectedAlertPresentException as ex1:
print("Güzergah bilgilerinde hata meydana geldi. Kontrol ederek tekrar deneyiniz. İstasyonları doğru girdiğinizden emin olunuz")
self.driver.quit()
exit()