Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timetable URL error #5

Closed
KarimullinArthur opened this issue Oct 28, 2024 · 3 comments · Fixed by #6
Closed

Timetable URL error #5

KarimullinArthur opened this issue Oct 28, 2024 · 3 comments · Fixed by #6
Labels
bug Something isn't working

Comments

@KarimullinArthur
Copy link
Owner

При запросе на адрес:

https://lk.sut.ru/cabinet/project/cabinet/forms/raspisanie.php?week=11

Из питона(и из аиохттп, и из requests) получаем:

<div class="container-fluid"><div class="breadcrumbs"><span style="font: 13px Tahoma,Arial;"><a href="ERRNO: 8
TEXT: Undefined index: link_url
LOCATION: /home/data/html/projects/project/cabinet/forms/raspisanie.php
LINE: 99

Из курла, и самого браузера все ок.

curl -v --cookie "miden=jsecl7o0isa52nk9gtfl9jl4es" https://lk.sut.ru/cabinet/project/cabinet/forms/raspisanie.php\?week\=12 --user-agent "BONCHMUSTDIE" | iconv --from-code WINDOWS-1251 --to-code UTF-8

На

https://lk.sut.ru/cabinet/project/cabinet/forms/raspisanie_all.php?schet=205.2425%2F1&type_z=1&faculty=57185&kurs=2&group=56204

Выплювывает

<div class="container-fluid"><div class="breadcrumbs"><span style="font: 13px Tahoma,Arial;"><a href="ERRNO: 8
TEXT: Undefined index: link_url
LOCATION: /home/data/html/projects/project/cabinet/forms/raspisanie_all.php
LINE: 83
@KarimullinArthur KarimullinArthur converted this from a draft issue Oct 28, 2024
@KarimullinArthur KarimullinArthur added the bug Something isn't working label Oct 28, 2024
@KarimullinArthur
Copy link
Owner Author

Натыкал новые результаты. Курл и питон тут не причём, как я и изначально думал. Дело в том где генерится токен. Если токен был сгенерен в браузере, то всё супер.

З.Ы. энивей нужно допилить парсер в питоне, а то он их не кушает, там немного другая структура.

@iwtcode
Copy link
Collaborator

iwtcode commented Feb 4, 2025

async def login(self, email: str, password: str) -> bool:
    AUTH = f'https://lk.sut.ru/cabinet/lib/autentificationok.php?users={email}&parole={password}'
    CABINET = 'https://lk.sut.ru/cabinet/'
    
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(CABINET) as response:
                response.raise_for_status()
                self.cookies = response.cookies
                async with session.post(AUTH) as response:
                    response.raise_for_status()
                    text = await response.text()
                    if text == '1':
                        async with session.get(CABINET) as response:
                            response.raise_for_status()
                            return True
                    else:
                        return False
    except Exception as e:
        return False
async def raspisanie(self):
    URL = 'https://lk.sut.ru/cabinet/project/cabinet/forms/raspisanie_all.php'

    async with aiohttp.ClientSession() as session:
        async with session.get(URL, cookies=self.cookies) as response:
            response.raise_for_status()
            text = await response.text()
            with open('raspisanie_all.html', 'w') as f:
                f.write(text)
            return text

@KarimullinArthur
Copy link
Owner Author

@iwtcode
Афигеть, друг, ты сделал меня счастливым. Спасибо, реально.

Я догадывался, что возможно что-то с редиректом, или какая-то другая тривиальная проблема, но времени не было с этим возиться. Но, чему я действительно офигел, что кто-то заметил мою, репу, чекнул сорцы, и отписал в ишью. Мужик, пасиба.

З.ы. всё работает, закрою ишью как кину pr, заодно смержу #4, и сразу выкачу релиз.
А я только навонял в ридми https://github.com/KarimullinArthur/bonchcli что надо закрыть эту ишьюшку.

respect++

@KarimullinArthur KarimullinArthur linked a pull request Feb 6, 2025 that will close this issue
@github-project-automation github-project-automation bot moved this from Backlog to Done in BonchAPI Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants