-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrp.py
131 lines (120 loc) · 5.53 KB
/
scrp.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- coding: utf-8 -*-
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from time import sleep
from telegram import ReplyKeyboardMarkup
import app
reply_keyboard = [['20'],
['19'],
['18'],
['17'],
['16'],
['15'],
['14'],
['13'],
['12']]
markup = ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)
def main(user_data, bot, update):
with open('n.txt', 'w') as f:
f.write('1')
driver = webdriver.PhantomJS()
try:
driver.get("http://sada.guilan.ac.ir/Dashboard.aspx")
if 'sada.guilan.ac.ir/GoToDashboard.aspx' in driver.current_url:
driver.find_element_by_class_name('refreshDash').click()
wait = WebDriverWait(driver, 10)
elem = wait.until(ec.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'ورود به س')))
elem.click()
elem = wait.until(ec.presence_of_element_located((By.ID, 'iframe_040101')))
driver.get(elem.get_property('src'))
elem = driver.find_element_by_name('SSMUsername_txt')
elem.send_keys(user_data['username'])
elem = driver.find_element_by_name('SSMPassword_txt')
elem.send_keys(user_data['password'] + Keys.ENTER)
elem = wait.until(ec.presence_of_element_located((By.ID, 'FLASH_URL_TAB_ID')))
elem.click()
elem22 = wait.until(ec.presence_of_element_located((By.ID, 'iframe_FLASH_URL_TAB_ID')))
driver.get(elem22.get_property('src'))
elemfs = wait.until(ec.presence_of_all_elements_located((By.CLASS_NAME, 'Eval-grid')))
while True:
elemfs[0].click()
sleep(2)
tabs = driver.window_handles
driver.close()
driver.switch_to.window(tabs[1])
elems = wait.until(ec.presence_of_all_elements_located((By.CSS_SELECTOR, 'input[type="button"]')))
while True:
elems[0].click()
sleep(2)
tabs = driver.window_handles
print(tabs)
driver.switch_to.window(tabs[1])
elem = wait.until(ec.presence_of_element_located((By.ID, 'InfoLbl')))
print(elem.text)
bot.send_message(chat_id=update.message.chat.id, text= elem.text + '\n نمره رو بزن:' , reply_markup=markup)
t = 0
print('tt')
while t <= 20:
print('t1')
if user_data['nomre'] == -1:
if t == 20:
reply_keyboard2 = [['فرستادن نام کاربری و کلمه عبور (username, password)'],
['شروع']]
markup2 = ReplyKeyboardMarkup(reply_keyboard2, one_time_keyboard=True)
bot.send_message(chat_id=update.message.chat.id, text='خب تایمت تموم شد! بای بای!', reply_markup=markup2)
driver.close()
with open('n.txt', 'w') as f:
f.write('0')
exit()
sleep(1)
t += 1
else:
break
nomre = user_data['nomre']
print(nomre)
els = wait.until(ec.presence_of_all_elements_located((By.TAG_NAME, 'input')))
avali = 1
for el in els:
if avali == 1:
if nomre == 8:
nomre -= 1
else:
nomre += 1
avali = 0
if el.get_attribute('id')[:3] == 'rb' + str(nomre):
el.click()
elem = wait.until(ec.presence_of_element_located((By.ID, 'btnContinue')))
elem.click()
sleep(2)
driver.close()
driver.switch_to.window(tabs[0])
user_data['nomre'] = -1
if len(elems) == 1:
break
elems = wait.until(ec.presence_of_all_elements_located((By.CSS_SELECTOR, 'input[type="button"]')))
if len(elemfs) == 1:
break
driver.get(elem22.get_property('src'))
elemfs = wait.until(ec.presence_of_all_elements_located((By.CLASS_NAME, 'Eval-grid')))
bot.send_message(chat_id=update.message.chat.id, text='خب تموم شششددددد !!!!!')
driver.close()
with open('n.txt', 'w') as f:
f.write('0')
exit(0)
except Exception as e:
print(e.args)
print(user_data)
reply_keyboard2 = [['فرستادن نام کاربری و کلمه عبور (username, password)'],
['شروع']]
markup2 = ReplyKeyboardMarkup(reply_keyboard2, one_time_keyboard=True)
bot.send_message(chat_id=update.message.chat.id, text='به ارور برخوردیم! شاید فرم ارزشیابی تموم شده باشه شایدم یوزر پسورد اشتباه باشه', reply_markup=markup2)
try:
driver.close()
with open('n.txt', 'w') as f:
f.write('0')
except Exception as e:
print(e.args)
pass