mirror of
https://github.com/house-of-vanity/fesmoo_perdoliq.git
synced 2025-07-07 14:04:06 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
decd96fe5c | |||
a5ac105177 | |||
4b0a8a7675 | |||
2ece55bd6f | |||
45177e13e4 | |||
d348989afb | |||
c631da43a1 | |||
6ab5e06c5e | |||
ab7aef8da7 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# configs
|
||||
creds.ini
|
||||
baraban.build/
|
||||
tg_settings.py
|
||||
*.swp
|
||||
*.swo
|
||||
|
@ -7,5 +7,5 @@ RUN apt-get update && \
|
||||
|
||||
WORKDIR /usr/share/fesmoo_perdoliq
|
||||
COPY ./*py /usr/share/fesmoo_perdoliq/
|
||||
CMD python3 baraban.py
|
||||
CMD python3 bot_keys.py
|
||||
|
||||
|
130
baraban.py
130
baraban.py
@ -9,46 +9,12 @@ import os
|
||||
import sys
|
||||
import logging
|
||||
import threading
|
||||
import telegram
|
||||
from telegram.error import NetworkError, Unauthorized
|
||||
from time import sleep
|
||||
try:
|
||||
TOKEN = os.environ["TG_TOKEN"]
|
||||
except:
|
||||
print("You have to set env var TG_TOKEN with bot token.")
|
||||
sys.exit(1)
|
||||
try:
|
||||
if os.environ["DRYRUN"]:
|
||||
from dryrun import Perdoliq
|
||||
except:
|
||||
from main import Perdoliq
|
||||
|
||||
update_id = None
|
||||
from main import Perdoliq
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the bot."""
|
||||
global update_id
|
||||
# Telegram Bot Authorization Token
|
||||
bot = telegram.Bot(TOKEN)
|
||||
|
||||
# get the first pending update_id,
|
||||
# this is so we can skip over it in case
|
||||
# we get an "Unauthorized" exception.
|
||||
try:
|
||||
update_id = bot.get_updates()[0].update_id
|
||||
except IndexError:
|
||||
update_id = None
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
while True:
|
||||
try:
|
||||
handle_update(bot)
|
||||
except NetworkError:
|
||||
sleep(1)
|
||||
except Unauthorized:
|
||||
# The user has removed or blocked the bot.
|
||||
update_id += 1
|
||||
list_test('4016014', '40403')
|
||||
|
||||
|
||||
def perdoliq(username, password, subj, test, acc, is_delayed):
|
||||
@ -69,98 +35,6 @@ def list_test(username, password):
|
||||
return "Exception: " + str(e)
|
||||
|
||||
|
||||
def handle_update(bot):
|
||||
"""Echo the message the user sent."""
|
||||
global update_id
|
||||
# Request updates after the last update_id
|
||||
for update in bot.get_updates(offset=update_id, timeout=10):
|
||||
update_id = update.update_id + 1
|
||||
|
||||
if update.message:
|
||||
# if there is and update, process it in threads
|
||||
t = threading.Thread(target=do_action, args=(update,))
|
||||
t.start()
|
||||
|
||||
def do_action(update):
|
||||
try:
|
||||
s = update.message.text.split()
|
||||
except:
|
||||
return 1
|
||||
if s[0] == '/resolve':
|
||||
if len(s) != 7:
|
||||
update.message.reply_markdown("Missing operand... Try again")
|
||||
update.message.reply_markdown("Usage: */resolve <user[text]> "\
|
||||
"<pass[text]> <subj[int]> <test[int]> "\
|
||||
"<accuracy[0-100]> <commit[1/0]>*")
|
||||
return False
|
||||
|
||||
msg = "Please wait. If you have chosen commit=1, so test "\
|
||||
"going to be resolved in about 20 minutes and will "\
|
||||
"be commited automatically, otherwise it will take "\
|
||||
"about a 2 minutes and you have to "\
|
||||
"commit it by yourself. Just wait. PS you have "\
|
||||
"chosen subj %s "\
|
||||
"test %s and accuracy %s" % (s[3], s[4], s[5])
|
||||
update.message.reply_text(msg)
|
||||
update.message.reply_text("You cannot resolve more than "\
|
||||
"one test in the same time."\
|
||||
"Одновременно решать более одного теста невозможно,"\
|
||||
" вы испортите результаты обоих тестов.")
|
||||
perdoliq(s[1], s[2], s[3], s[4], s[5], s[6])
|
||||
update.message.reply_text("It's done. Check your test because "\
|
||||
"i disclaim any responsibility.")
|
||||
elif s[0] == '/list':
|
||||
try:
|
||||
if len(s) == 3:
|
||||
update.message.reply_text("Fetching subjects...")
|
||||
sleep(1)
|
||||
tests = list_test(s[1], s[2])
|
||||
msg = "Here is an available subjects:\n```"
|
||||
i = 0
|
||||
for subj in tests:
|
||||
tests_count = len(tests[subj])
|
||||
msg = msg + (" [%s] %s (%s tests)\n" % (i, subj, tests_count))
|
||||
i += 1
|
||||
# j = 0
|
||||
# for test in tests[subj]:
|
||||
# msg = msg + (" [%s] %s\n" % (j, test))
|
||||
# j += 1
|
||||
update.message.reply_markdown(msg + "```\n Pay attention to "\
|
||||
"numbers in brackets \[..] *Here is subj or test numbers*")
|
||||
elif len(s) == 4:
|
||||
update.message.reply_text("Fetching tests...")
|
||||
sleep(1)
|
||||
tests = list_test(s[1], s[2])
|
||||
i = int(s[3])
|
||||
msg = "Here is an available tests:\n"
|
||||
j = 0
|
||||
for subj in tests:
|
||||
if j == i:
|
||||
msg = msg + ("``` *** %s ***\n----------\n" % subj)
|
||||
k = 0
|
||||
for test in tests[subj]:
|
||||
msg = msg + ("[%s] %s\n" % (k, test))
|
||||
k += 1
|
||||
j += 1
|
||||
update.message.reply_markdown(msg + "```\n Pay attention to "\
|
||||
"numbers in brackets \[..] *Here is subj or test numbers*")
|
||||
else:
|
||||
update.message.reply_markdown("Usage: */list <user[text]>"\
|
||||
" <pass[text]>*")
|
||||
return False
|
||||
except:
|
||||
update.message.reply_markdown("Usage: */list <user[text]>"\
|
||||
" <pass[text]>*")
|
||||
return False
|
||||
else:
|
||||
update.message.reply_markdown("Possible commands: */resolve, /list*")
|
||||
update.message.reply_markdown("Usage: */resolve <user[text]> "\
|
||||
"<pass[text]> <subj[int]> <test[int]> "\
|
||||
"<accuracy[0-100]> <commit[1/0]>*")
|
||||
update.message.reply_markdown("Usage: */list <user[text]> "\
|
||||
"<pass[text]>*")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
|
92
bot.py
92
bot.py
@ -6,16 +6,17 @@ on the telegram.ext bot framework.
|
||||
This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import threading
|
||||
import telegram
|
||||
from telegram.error import NetworkError, Unauthorized
|
||||
from time import sleep
|
||||
try:
|
||||
import tg_settings
|
||||
TOKEN = os.environ["TG_TOKEN"]
|
||||
except:
|
||||
print("You have to create tg_settings.py. See tg_settings.py.example.")
|
||||
os.exit(1)
|
||||
print("You have to set env var TG_TOKEN with bot token.")
|
||||
sys.exit(1)
|
||||
try:
|
||||
if os.environ["DRYRUN"]:
|
||||
from dryrun import Perdoliq
|
||||
@ -29,7 +30,6 @@ def main():
|
||||
"""Run the bot."""
|
||||
global update_id
|
||||
# Telegram Bot Authorization Token
|
||||
TOKEN = tg_settings.TG_TOKEN
|
||||
bot = telegram.Bot(TOKEN)
|
||||
|
||||
# get the first pending update_id,
|
||||
@ -86,9 +86,83 @@ def do_action(update):
|
||||
s = update.message.text.split()
|
||||
except:
|
||||
return 1
|
||||
# if s[0] == '/resolve':
|
||||
# return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
if s[0] == '/resolve':
|
||||
if len(s) != 7:
|
||||
update.message.reply_markdown("Missing operand... Try again")
|
||||
update.message.reply_markdown("Usage: */resolve <user[text]> "\
|
||||
"<pass[text]> <subj[int]> <test[int]> "\
|
||||
"<accuracy[0-100]> <commit[1/0]>*")
|
||||
return False
|
||||
|
||||
msg = "Please wait. If you have chosen commit=1, so test "\
|
||||
"going to be resolved in about 20 minutes and will "\
|
||||
"be commited automatically, otherwise it will take "\
|
||||
"about a 2 minutes and you have to "\
|
||||
"commit it by yourself. Just wait. PS you have "\
|
||||
"chosen subj %s "\
|
||||
"test %s and accuracy %s" % (s[3], s[4], s[5])
|
||||
update.message.reply_text(msg)
|
||||
update.message.reply_text("You cannot resolve more than "\
|
||||
"one test in the same time."\
|
||||
"Одновременно решать более одного теста невозможно,"\
|
||||
" вы испортите результаты обоих тестов.")
|
||||
perdoliq(s[1], s[2], s[3], s[4], s[5], s[6])
|
||||
update.message.reply_text("It's done. Check your test because "\
|
||||
"i disclaim any responsibility.")
|
||||
elif s[0] == '/list':
|
||||
try:
|
||||
if len(s) == 3:
|
||||
update.message.reply_text("Fetching subjects...")
|
||||
sleep(1)
|
||||
tests = list_test(s[1], s[2])
|
||||
msg = "Here is an available subjects:\n```"
|
||||
i = 0
|
||||
for subj in tests:
|
||||
tests_count = len(tests[subj])
|
||||
msg = msg + (" [%s] %s (%s tests)\n" % (i, subj, tests_count))
|
||||
i += 1
|
||||
# j = 0
|
||||
# for test in tests[subj]:
|
||||
# msg = msg + (" [%s] %s\n" % (j, test))
|
||||
# j += 1
|
||||
update.message.reply_markdown(msg + "```\n Pay attention to "\
|
||||
"numbers in brackets \[..] *Here is subj or test numbers*")
|
||||
elif len(s) == 4:
|
||||
update.message.reply_text("Fetching tests...")
|
||||
sleep(1)
|
||||
tests = list_test(s[1], s[2])
|
||||
i = int(s[3])
|
||||
msg = "Here is an available tests:\n"
|
||||
j = 0
|
||||
for subj in tests:
|
||||
if j == i:
|
||||
msg = msg + ("``` *** %s ***\n----------\n" % subj)
|
||||
k = 0
|
||||
for test in tests[subj]:
|
||||
msg = msg + ("[%s] %s\n" % (k, test))
|
||||
k += 1
|
||||
j += 1
|
||||
update.message.reply_markdown(msg + "```\n Pay attention to "\
|
||||
"numbers in brackets \[..] *Here is subj or test numbers*")
|
||||
else:
|
||||
update.message.reply_markdown("Usage: */list <user[text]>"\
|
||||
" <pass[text]>*")
|
||||
return False
|
||||
except:
|
||||
update.message.reply_markdown("Usage: */list <user[text]>"\
|
||||
" <pass[text]>*")
|
||||
return False
|
||||
else:
|
||||
update.message.reply_markdown("Possible commands: */resolve, /list*")
|
||||
update.message.reply_markdown("Usage: */resolve <user[text]> "\
|
||||
"<pass[text]> <subj[int]> <test[int]> "\
|
||||
"<accuracy[0-100]> <commit[1/0]>*")
|
||||
update.message.reply_markdown("Usage: */list <user[text]> "\
|
||||
"<pass[text]>*")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except:
|
||||
pass
|
||||
|
257
bot_keys.py
Normal file
257
bot_keys.py
Normal file
@ -0,0 +1,257 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Simple Bot to reply to Telegram messages.
|
||||
This is built on the API wrapper, see echobot2.py to see the same example built
|
||||
on the telegram.ext bot framework.
|
||||
This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import threading
|
||||
from telegram import *
|
||||
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
|
||||
from telegram.error import NetworkError, Unauthorized
|
||||
from time import sleep
|
||||
from functools import wraps
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
from pprint import pprint
|
||||
try:
|
||||
TOKEN = os.environ["TG_TOKEN"]
|
||||
except:
|
||||
print("You have to set env var TG_TOKEN with bot token.")
|
||||
sys.exit(1)
|
||||
try:
|
||||
if os.environ["DRYRUN"]:
|
||||
from dryrun import Perdoliq
|
||||
except:
|
||||
from main import Perdoliq
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
auth = dict()
|
||||
|
||||
cached_tests = dict()
|
||||
|
||||
def main():
|
||||
"""Run bot."""
|
||||
updater = Updater(TOKEN, use_context=True)
|
||||
dp = updater.dispatcher
|
||||
dp.add_handler(CallbackQueryHandler(button_handler))
|
||||
dp.add_handler(CommandHandler("login", login,
|
||||
pass_args=True,
|
||||
pass_job_queue=True,
|
||||
pass_chat_data=True))
|
||||
dp.add_handler(CommandHandler("list", list_,
|
||||
pass_args=True,
|
||||
pass_job_queue=True,
|
||||
pass_chat_data=True))
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
updater.start_polling()
|
||||
updater.idle()
|
||||
|
||||
def error(update, context):
|
||||
"""Log Errors caused by Updates."""
|
||||
LOG.warning('Update "%s" caused error "%s"', update, context.error)
|
||||
|
||||
def is_authorized(id_):
|
||||
def decorator(f):
|
||||
@wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
if args[0].effective_user.id not in auth:
|
||||
LOG.info(
|
||||
"User %s (%s) is new user. Redirecting to login.",
|
||||
args[0].effective_user.first_name,
|
||||
args[0].effective_user.id)
|
||||
return login_first(*args, **kwargs)
|
||||
ret = f(*args, **kwargs)
|
||||
return ret
|
||||
return wrapped
|
||||
return decorator
|
||||
|
||||
def login_first(update, context):
|
||||
msg = "Необходимо авторизоваться. "\
|
||||
"Авторизация будет сохранена "\
|
||||
"до момента перезагрузки бота. Пример: /login <user> <pass>"
|
||||
try:
|
||||
update.message.reply_text(msg)
|
||||
except:
|
||||
query = update.callback_query
|
||||
query.edit_message_text(msg)
|
||||
LOG.info("Going to login")
|
||||
|
||||
def login(update, context):
|
||||
user_id = update.effective_user.id
|
||||
message = update.message.text.split()
|
||||
if len(message) == 3:
|
||||
login = message[1]
|
||||
passwd = message[2]
|
||||
auth[user_id] = dict()
|
||||
auth[user_id]["login"] = login
|
||||
auth[user_id]["passwd"] = passwd
|
||||
update.message.reply_text("Учетные данные сохранены.")
|
||||
elif len(message) == 2 and message[1] == 'status':
|
||||
if user_id in auth:
|
||||
update.message.reply_text(
|
||||
"Вы авторизованы с данными: {} : {}***\n"\
|
||||
"Для обновления данных авторизуйтесь повторно.".format(
|
||||
auth[user_id]["login"],
|
||||
auth[user_id]["passwd"][0:2]))
|
||||
else:
|
||||
update.message.reply_text("Вы еще не авторизованы.")
|
||||
else:
|
||||
update.message.reply_text("Запрет! Попытка взлома! Делай так: "\
|
||||
"/login <user> <pass> или /login status")
|
||||
|
||||
|
||||
def perdoliq(username, password, subj, test, acc, submit=True, is_delayed=False):
|
||||
try:
|
||||
app = Perdoliq(username, password)
|
||||
app.auth()
|
||||
app.resolve(subj, test, acc, submit, is_delayed)
|
||||
except Exception as e:
|
||||
return "Exception: " + str(e)
|
||||
|
||||
def list_test(username, password):
|
||||
now = datetime.datetime.now()
|
||||
cache_name = f"{now.month}_{now.day}_{now.hour}"
|
||||
if cache_name in cached_tests:
|
||||
cache_username = cached_tests[cache_name].get(username, None)
|
||||
if cache_username:
|
||||
return cache_username
|
||||
try:
|
||||
app = Perdoliq(username, password)
|
||||
app.auth()
|
||||
tests = app.get_tests()
|
||||
if not cached_tests.get(cache_name, None):
|
||||
cached_tests[cache_name] = dict()
|
||||
cached_tests[cache_name][username] = tests
|
||||
return tests
|
||||
except Exception as e:
|
||||
return "Exception: " + str(e)
|
||||
|
||||
@is_authorized('list_')
|
||||
def list_(update, context):
|
||||
query = update.callback_query
|
||||
user_id = update.effective_user.id
|
||||
tests = list_test(auth[user_id]["login"], auth[user_id]["passwd"])
|
||||
keyboard = list()
|
||||
i = 1
|
||||
for subj in tests:
|
||||
tests_count = len(tests[subj])
|
||||
#msg = msg + (" [%s] %s (%s tests)\n" % (i, subj, tests_count))
|
||||
keyboard.append([InlineKeyboardButton(f"{i}. {subj}", callback_data=f"s_{i}")])
|
||||
i += 1
|
||||
keyboard.append([InlineKeyboardButton("Закрыть", callback_data=f"close")])
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
update.message.reply_text('Чо будем хакать?', reply_markup=reply_markup)
|
||||
|
||||
@is_authorized('button_handler')
|
||||
def button_handler(update, context):
|
||||
query = update.callback_query
|
||||
user_id = update.effective_user.id
|
||||
tests = list_test(auth[user_id]["login"], auth[user_id]["passwd"])
|
||||
if query.data.split('_')[0] == 'close':
|
||||
query.edit_message_text('Пака братишка')
|
||||
if query.data.split('_')[0] == 's': # subj
|
||||
data = query.data
|
||||
subj_num = query.data.split('_')[1]
|
||||
keyboard = list()
|
||||
subj_name = None
|
||||
j = 1 # subj number
|
||||
i = 1 # test number
|
||||
for subj in tests:
|
||||
LOG.debug("Checking: %s. %s is %s", subj, j, subj_num)
|
||||
if j != int(subj_num):
|
||||
j += 1
|
||||
continue
|
||||
else:
|
||||
LOG.info("Found needed subj: %s", subj)
|
||||
subj_name = subj
|
||||
for test in tests[subj]:
|
||||
LOG.info("Found test: %s", test)
|
||||
keyboard.append([
|
||||
InlineKeyboardButton(f"{i}. {test}",
|
||||
callback_data=f"t_{i}_{data}")])
|
||||
i += 1
|
||||
break
|
||||
keyboard.append([InlineKeyboardButton("Закрыть", callback_data=f"close")])
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
query.edit_message_text(
|
||||
f"Ok, решаем {subj_name}, а какой тест?",
|
||||
reply_markup=reply_markup)
|
||||
|
||||
if query.data.split('_')[0] == 't': # test
|
||||
data = query.data
|
||||
keyboard = [[], []]
|
||||
in_a_row = 4
|
||||
for p in range(0, 101, 5):
|
||||
if len(keyboard[-1]) == in_a_row:
|
||||
keyboard.append(list())
|
||||
keyboard[-1].append(InlineKeyboardButton(f"{p}", callback_data=f"p_{p}_{data}"))
|
||||
|
||||
keyboard.append([InlineKeyboardButton("Закрыть", callback_data=f"close")])
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
query.edit_message_text("Ok, а какая точность?", reply_markup=reply_markup)
|
||||
|
||||
if query.data.split('_')[0] == 'm': # autosubmit
|
||||
data = query.data
|
||||
keyboard = [[
|
||||
InlineKeyboardButton(f"Быстро", callback_data=f"d_0_{data}"),
|
||||
InlineKeyboardButton(f"С задержками", callback_data=f"d_1_{data}"),]]
|
||||
keyboard.append([InlineKeyboardButton("Закрыть", callback_data=f"close")])
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
query.edit_message_text(
|
||||
"Решить тест быстро или с задержками, типа я думал над ответом.",
|
||||
reply_markup=reply_markup)
|
||||
|
||||
if query.data.split('_')[0] == 'p': # precision
|
||||
data = query.data
|
||||
keyboard = [[
|
||||
InlineKeyboardButton(f"Завершить", callback_data=f"m_1_{data}"),
|
||||
InlineKeyboardButton(f"Не завершать", callback_data=f"m_0_{data}"),]]
|
||||
keyboard.append([InlineKeyboardButton("Close", callback_data=f"close")])
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
query.edit_message_text(
|
||||
"Завершить тест автоматически после решения или оставить для проверки?",
|
||||
reply_markup=reply_markup)
|
||||
|
||||
if query.data.split('_')[0] == 'd': # is_delayed
|
||||
data = query.data
|
||||
LOG.info(data)
|
||||
# d_0_m_1_p_100_t_1_s_10
|
||||
subj = query.data.split('_')[9]
|
||||
test = query.data.split('_')[7]
|
||||
precision = query.data.split('_')[5]
|
||||
submit = bool(int(query.data.split('_')[3]))
|
||||
delay = bool(int(query.data.split('_')[1]))
|
||||
query.edit_message_text(
|
||||
"Опять работа... "\
|
||||
"Пока я решаю тест ЗАПРЕЩЕНО "\
|
||||
"пользоваться сайтом с тестами. "\
|
||||
"Резултат будет испорчен.")
|
||||
perdoliq(
|
||||
auth[user_id]["login"],
|
||||
auth[user_id]["passwd"],
|
||||
int(subj)-1,
|
||||
int(test)-1,
|
||||
precision,
|
||||
submit,
|
||||
delay)
|
||||
query.edit_message_text("Так! Я все решил.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except Exception as e:
|
||||
LOG.error("%s", e)
|
||||
pass
|
45
main.py
45
main.py
@ -16,30 +16,45 @@ class Perdoliq:
|
||||
self.SessionId = ''
|
||||
self.name = ''
|
||||
self.subjects = {}
|
||||
|
||||
@staticmethod
|
||||
def get_secrets(response, input_id):
|
||||
soup = BeautifulSoup(response.text, "html.parser")
|
||||
try:
|
||||
secret = soup.find(id=input_id).get('value', '')
|
||||
except AttributeError:
|
||||
secret = ''
|
||||
logging.debug(f'*** Found {input_id}: {secret}')
|
||||
return secret
|
||||
|
||||
# make auth
|
||||
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)
|
||||
self.SessionId = r.cookies.get('ASP.NET_SessionId', None)
|
||||
logging.info('ASP.NET_SessionId for curtain session is %s',
|
||||
self.SessionId)
|
||||
|
||||
data={
|
||||
'ctl00$MainContent$UserText': self.username,
|
||||
'ctl00$MainContent$PassText': self.password,
|
||||
'ctl00_MainContent_ToolkitScriptManager1_HiddenField': '',
|
||||
'ctl00$MainContent$ASPxButton1': '',
|
||||
'__EVENTTARGET': '',
|
||||
'__EVENTARGUMENT': '',
|
||||
'__VIEWSTATE': self.get_secrets(r, '__VIEWSTATE'),
|
||||
'__VIEWSTATEGENERATOR': self.get_secrets(r, '__VIEWSTATEGENERATOR'),
|
||||
'__EVENTVALIDATION': self.get_secrets(r, '__EVENTVALIDATION'),
|
||||
#'DXScript': get_secrets(r, 'DXScript'),
|
||||
}
|
||||
r = requests.post(
|
||||
settings.fesmu_root_url,
|
||||
data=settings.merge(
|
||||
settings.scam_data_1, {
|
||||
'ctl00$MainContent$TextBox1': self.username,
|
||||
'ctl00$MainContent$TextBox2': self.password,
|
||||
}),
|
||||
data = data,
|
||||
headers=settings.headers,
|
||||
cookies={'ASP.NET_SessionId': self.SessionId})
|
||||
|
||||
r = requests.get(
|
||||
settings.fesmu_root_url + 'startstu.aspx',
|
||||
cookies={'ASP.NET_SessionId': self.SessionId})
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
#print("****** ", soup)
|
||||
_p = re.compile(',.*$')
|
||||
self.name = _p.sub(
|
||||
'', soup.find(id="ctl00_MainContent_Label1").get_text())[14:]
|
||||
@ -225,8 +240,10 @@ class Perdoliq:
|
||||
data=settings.scam_data_10,
|
||||
cookies={'ASP.NET_SessionId': self.SessionId})
|
||||
|
||||
def resolve(self, subj, test, accuracy, is_delayed=False):
|
||||
def resolve(self, subj, test, accuracy=100, submit=False, is_delayed=False):
|
||||
# renew auth
|
||||
logging.info(
|
||||
f"Resolving subj {subj}, test {test}, acc {accuracy}, submit {submit}, delay {is_delayed}")
|
||||
self.auth()
|
||||
# get count of questions
|
||||
q_count = self.start_test(subj, test)
|
||||
@ -257,5 +274,5 @@ class Perdoliq:
|
||||
self.answer(i, prediction)
|
||||
|
||||
# make autocommit
|
||||
if is_delayed == True:
|
||||
if submit == True:
|
||||
self.finish_test()
|
||||
|
9
reqs.txt
9
reqs.txt
@ -1,7 +1,4 @@
|
||||
# python3 only
|
||||
pip install requests
|
||||
|
||||
pip install beautifulsoup4
|
||||
|
||||
pip install python-telegram-bot
|
||||
requests
|
||||
beautifulsoup4
|
||||
python-telegram-bot
|
||||
|
||||
|
48
settings.py
48
settings.py
@ -6,32 +6,32 @@ def merge(x, y):
|
||||
z.update(y) # modifies z with y's keys and values & returns None
|
||||
return z
|
||||
|
||||
headers = {
|
||||
"Host": "www.fesmu.ru",
|
||||
"Connection": "keep-alive",
|
||||
"Content-Length": '896',
|
||||
"Cache-Control": "max-age=0",
|
||||
"Origin": "http://www.fesmu.ru",
|
||||
"Upgrade-Insecure-Requests": '1',
|
||||
"DNT": '1',
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||
"Referer": "http://www.fesmu.ru/eport/eport/",
|
||||
"Accept-Encoding": "gzip, deflate",
|
||||
"Accept-Language": "en-US,en;q=0.9,ru;q=0.8,zh-CN;q=0.7,zh;q=0.6",
|
||||
}
|
||||
|
||||
|
||||
scam_data_1 = {
|
||||
'ctl00$MainContent$UserText':
|
||||
'',
|
||||
'ctl00$MainContent$PassText':
|
||||
'',
|
||||
'__EVENTTARGET':
|
||||
'',
|
||||
'ctl00_MainContent_ToolkitScriptManager1_HiddenField':
|
||||
'',
|
||||
'__EVENTARGUMENT':
|
||||
'',
|
||||
'__VIEWSTATE':
|
||||
'/wEPDwUKLTQ4NzYwNDEzOQ9kFgJmD2QWAgIDD2QWAgIBD2QWAgIFDw8WAh4EVGV4dAVA0KHQtdC50YfQsNGBINC/0L7Qu9GM0LfQvtCy0LDRgtC10LvQtdC5INC90LAg0L/QvtGA0YLQsNC70LU6IDE0OWRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYEBR1jdGwwMCRNYWluQ29udGVudCRBU1B4QnV0dG9uMQUdY3RsMDAkTWFpbkNvbnRlbnQkQVNQeEJ1dHRvbjMFHWN0bDAwJE1haW5Db250ZW50JEFTUHhCdXR0b24yBR1jdGwwMCRNYWluQ29udGVudCRBU1B4QnV0dG9uNCwdlTOn/Y3tYt2bGQcxN1Ayzl4rDNlkVU6tnQ6bR4Dx',
|
||||
'__VIEWSTATEGENERATOR':
|
||||
'73D4C735',
|
||||
'__EVENTVALIDATION':
|
||||
'/wEdAAcLL4CnFN6qTtcjF0fQcU/LUN0eEH6RAZcaSKVdt8S4X7osef1mutGT26WuFCdWwFYhaXIQoXEs7lyT4XozQ4OInWK1mn7aEBNhVaP9v76fJNxRJK/kVxlULg0AsW337/IhsIAW9IW5kv7Tf6wiSWjxVWBHkOt1REFfEOsSpvCk8uTD/X8OKiSobFuKW+nh/Sg=',
|
||||
'ctl00$MainContent$ASPxButton2':
|
||||
'',
|
||||
'ctl00$MainContent$TextBox3':
|
||||
'',
|
||||
'ctl00$MainContent$TextBox4':
|
||||
'',
|
||||
'DXScript':
|
||||
'1_42,1_75,2_27'
|
||||
'ctl00_MainContent_ToolkitScriptManager1_HiddenField': '',
|
||||
# '__EVENTTARGET': '',
|
||||
# '__EVENTARGUMENT': '',
|
||||
'__VIEWSTATE': '/wEPDwUKLTM5Mjc2OTQzMQ9kFgJmD2QWAgIDD2QWAgIBD2QWAgIFDw8WAh4EVGV4dAW7AdCX0LAg0YHRg9GC0LrQuCDRg9C90LjQutCw0LvRjNC90YvRhSDQsNCy0YLQvtGA0LjQt9C40YDQvtCy0LDQvdC90YvRhSDQv9C+0LvRjNC30L7QstCw0YLQtdC70LXQuSDQvdCwINC/0L7RgNGC0LDQu9C1OiAyNjY3PGJyLyA+0KHQtdC50YfQsNGBINC/0L7QtNC60LvRjtGH0LXQvdC40Lkg0Log0L/QvtGA0YLQsNC70YM6IDUzOTVkZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAQUdY3RsMDAkTWFpbkNvbnRlbnQkQVNQeEJ1dHRvbjFA+y5c2mr9OLuyebEMey8lwZdb51brZaJ6iXIvwaVWpg==',
|
||||
# '__VIEWSTATEGENERATOR': '73D4C735',
|
||||
'__EVENTVALIDATION': '/wEdAAMqLyJo1lw62U+c0YXYJTJCUN0eEH6RAZcaSKVdt8S4X7osef1mutGT26WuFCdWwFaDQnYjJQ2/uhzVMKV3HbBN40+h9rsbvZwG3sNsqevEUg==',
|
||||
'ctl00$MainContent$ASPxButton1': '',
|
||||
# 'DXScript': '1_42,1_75,2_27',
|
||||
}
|
||||
|
||||
scam_data_2 = {
|
||||
|
Reference in New Issue
Block a user