-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8558480
Showing
6 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Venv/ | ||
.idea/ | ||
__pycache__/ | ||
.git/ | ||
config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# stankin-bot | ||
|
||
### This bot is for better edu.stankin.ru exp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import requests | ||
from lxml import html | ||
import re | ||
import datetime | ||
|
||
|
||
def get_logintoken(login_url, session_requests): | ||
result = session_requests.get(login_url) | ||
tree = html.fromstring(result.content) | ||
return list(set(tree.xpath("//input[@name='logintoken']/@value")))[0] | ||
|
||
|
||
def login(session_requests): | ||
payload = {"username": "st119181", | ||
"password": "St000QsYss%", | ||
"logintoken": "rE4k5W4LgoOMKR7jJUFuQzQD1dJ4s18g"} | ||
login_url = "https://edu.stankin.ru/login/" | ||
payload['logintoken'] = get_logintoken(login_url, session_requests) | ||
|
||
result = session_requests.post( | ||
login_url, | ||
data=payload, | ||
headers=dict(referer=login_url) | ||
) | ||
return session_requests | ||
|
||
|
||
def parse_result(result): | ||
now = datetime.datetime.now() | ||
p = re.compile(b'\xd0\x98\xd0\x94\xd0\x91-19-03 ') | ||
|
||
match = p.search(result.content) | ||
print(match) | ||
first = match.span()[0] - 54 | ||
last = match.span()[0] - 2 | ||
return result.content[first:last].decode("utf-8") | ||
|
||
|
||
def get_url(): | ||
session_requests = requests.session() | ||
session_requests = login(session_requests) | ||
url = 'https://edu.stankin.ru/mod/forum/view.php?id=140959' | ||
result = session_requests.get( | ||
url, | ||
headers=dict(referer=url) | ||
) | ||
print(result.status_code) | ||
return parse_result(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(get_url()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import Enum | ||
|
||
|
||
class Classes(Enum): | ||
physics = "физика" | ||
sports = "физра" | ||
oop = "ооп" | ||
elteh = "элтех" | ||
probability_theory = "тервер" | ||
calc_math = "вычмат" | ||
hmi = "чмв" | ||
mo = "мо" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import Enum | ||
import sports_url | ||
|
||
class Urls(Enum): | ||
physics_url = "https://edu.stankin.ru/mod/forum/discuss.php?d=37245" | ||
sports_url = sports_url.get_url() | ||
probability_theory_url = "https://us04web.zoom.us/postattendee?id=3" | ||
oop_url = "https://us02web.zoom.us/j/87992120807?pwd=bktocTR1aGhFQks2OUU2V0QwcTRnUT09" | ||
elteh_url = "https://us04web.zoom.us/j/5452496132?pwd=UWdBRjlKdlNHSXNzZjIybXlVRzhnQT09" | ||
calc_math_url = "https://us02web.zoom.us/j/79640032120?pwd=ZXNpZmxGVXVSdFpxVWFTcUFIRitRZz09" | ||
hmi_url = "https://discord.gg/smDRAXqxMR" | ||
mo_url = "на мо ссылку не скину, там в дискорде сервер без приглашений(9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from config import group_id, api_token | ||
from vk_api import VkApi | ||
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType | ||
from urls import Urls | ||
from stankin_classes_alias import Classes | ||
import time | ||
|
||
class Bot: | ||
def __init__(self, group_id, token): | ||
self.group_id = group_id | ||
self.token = token | ||
self.vk = VkApi(token=token) | ||
self.api = self.vk.get_api() | ||
self.long_poller = VkBotLongPoll(self.vk, group_id=self.group_id) | ||
self.time_stamp = time.time() | ||
|
||
def _send(self, url: Urls, event): | ||
try: | ||
self.api.messages.send(message="ща скину...", | ||
random_id=event.object.random_id, | ||
peer_id=event.object.peer_id) | ||
self.api.messages.send(message=url.value, | ||
random_id=event.object.random_id, | ||
peer_id=event.object.peer_id) | ||
except Exception: | ||
self.api.messages.send(message="чёт ссылку не нашел...", | ||
random_id=event.object.random_id, | ||
peer_id=event.object.peer_id) | ||
|
||
def _update_sports_url(self): | ||
if (time.time() - self.time_stamp) / 1800 >= 1: | ||
Urls.sports_url.value = sports_url.get_url() | ||
print(f"sports link had been updated: {Urls.sports_url.value}") | ||
|
||
|
||
def send_sports_url(self, event): | ||
self._send(Urls.sports_url, event) | ||
|
||
def send_physics_url(self, event): | ||
self._send(Urls.physics_url, event) | ||
|
||
def send_probability_theory_url(self, event): | ||
self._send(Urls.probability_theory_url, event) | ||
|
||
def send_oop_url(self, event): | ||
self._send(Urls.oop_url, event) | ||
|
||
def send_elteh_url(self, event): | ||
self._send(Urls.elteh_url, event) | ||
|
||
def send_calc_math_url(self, event): | ||
self._send(Urls.calc_math_url, event) | ||
|
||
def send_hmi_url(self, event): | ||
self._send(Urls.hmi_url, event) | ||
|
||
def send_mo_url(self, event): | ||
self._send(Urls.mo_url, event) | ||
|
||
def _on_event(self, event): | ||
cmd = event.object.text.lower() | ||
if event.type == VkBotEventType.MESSAGE_NEW: | ||
if Classes.sports.value in cmd: | ||
self.send_sports_url(event) | ||
if Classes.physics.value in cmd: | ||
self.send_physics_url(event) | ||
if Classes.probability_theory.value in cmd: | ||
self.send_probability_theory_url(event) | ||
if Classes.elteh.value in cmd: | ||
self.send_elteh_url(event) | ||
if Classes.oop.value in cmd: | ||
self.send_oop_url(event) | ||
if Classes.calc_math.value in cmd: | ||
self.send_calc_math_url(event) | ||
if Classes.hmi.value in cmd: | ||
self.send_hmi_url(event) | ||
if Classes.mo.value in cmd: | ||
self.send_mo_url(event) | ||
else: | ||
print(f'can not proceed {event.type}') | ||
|
||
def run(self): | ||
try: | ||
for event in self.long_poller.listen(): | ||
try: | ||
self._update_sports_url() | ||
self._on_event(event) | ||
except Exception as err: | ||
print(err) | ||
except Exception as err: | ||
print(err) | ||
print(self.long_poller.listen()) | ||
|
||
|
||
if __name__ == '__main__': | ||
bot = Bot(group_id, api_token) | ||
bot.run() |