Files
fesmoo_perdoliq/main.py

92 lines
3.4 KiB
Python
Raw Normal View History

2018-04-30 00:42:47 +03:00
import requests
import settings
import logging
2018-04-30 01:06:17 +03:00
import re
2018-04-30 00:42:47 +03:00
from bs4 import BeautifulSoup
2018-04-30 01:06:17 +03:00
logging.basicConfig(level=logging.INFO)
2018-04-30 00:42:47 +03:00
class Main:
def __init__(self, username, password):
self.password = password
self.username = username
self.SessionId = ''
2018-04-30 01:06:17 +03:00
self.name = ''
2018-04-30 02:39:48 +03:00
self.subjects = {}
2018-04-30 00:42:47 +03:00
def auth(self):
r = requests.get(settings.fesmu_root_url)
for c in r.cookies:
if c.name == 'ASP.NET_SessionId':
self.SessionId = c.value
logging.info('ASP.NET_SessionId for curtain session is %s',
c.value)
r = requests.post(
settings.fesmu_root_url,
data=settings.merge(
2018-04-30 02:39:48 +03:00
settings.scam_data_1, {
2018-04-30 01:06:17 +03:00
'ctl00$MainContent$TextBox1': self.username,
'ctl00$MainContent$TextBox2': self.password,
}),
2018-04-30 00:42:47 +03:00
cookies={'ASP.NET_SessionId': self.SessionId})
2018-04-30 01:06:17 +03:00
r = requests.get(
settings.fesmu_root_url + 'startstu.aspx',
cookies={'ASP.NET_SessionId': self.SessionId})
2018-04-30 00:42:47 +03:00
soup = BeautifulSoup(r.text, "html.parser")
2018-04-30 01:06:17 +03:00
_p = re.compile(',.*$')
self.name = _p.sub(
'', soup.find(id="ctl00_MainContent_Label1").get_text())[14:]
logging.info('Current user is %s', self.name)
def get_tests(self):
r = requests.get(
settings.fesmu_root_url + 'studtst1.aspx',
cookies={'ASP.NET_SessionId': self.SessionId})
2018-04-30 02:39:48 +03:00
soup = BeautifulSoup(r.text, "html.parser")
# parse subjects
for subject in soup.find_all(class_="dxeListBoxItem_Aqua dxeFTM"):
if subject.get_text() != '\xa0':
self.subjects.update({subject.get_text(): []})
logging.info('Found subject %s', subject.get_text())
logging.info('Found %s subjects', len(self.subjects))
# parse tests per subject
i = 0
for subject in self.subjects:
r = requests.post(
settings.fesmu_root_url + 'studtst1.aspx',
data=settings.merge(settings.scam_data_2,
{'ctl00$MainContent$hfPred': i}),
cookies={'ASP.NET_SessionId': self.SessionId})
soup = BeautifulSoup(r.text, "html.parser")
for test in soup.find_all(class_="dxeListBoxItem_Aqua dxeLTM"):
if test.get_text() != '\xa0':
self.subjects[subject].append(test.get_text())
logging.info('%s - Found test %s' % (subject,
test.get_text()))
i += 1
#print(self.subjects)
def start_test(self, pred, test):
# start test
r = requests.post(
settings.fesmu_root_url + 'studtst1.aspx',
data=settings.merge(
settings.scam_data_3, {
'ctl00$MainContent$hfPred': pred,
'ctl00$MainContent$hfTest': test
}),
cookies={'ASP.NET_SessionId': self.SessionId})
# get test content
r = requests.get(
settings.fesmu_root_url + 'studtst2.aspx',
cookies={'ASP.NET_SessionId': self.SessionId})
soup = BeautifulSoup(r.text, "html.parser")
_a = soup.find(class_='btntest')
q=[]
for i in _a.find_all(id=re.compile("ctl00_MainContent_ASPxButton.*_B")):
q.append(i)
return(len(q))