From 6daf55dce7298c813cd7b8562dd0f028ab4ec8d3 Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Tue, 27 Oct 2020 22:03:09 +0800 Subject: [PATCH] feat(umooc_simulator): support login --- .gitignore | 1 + README.md | 3 +++ umooc_client.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 umooc_client.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eba74f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fd241d3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# yomooc + +无论是 Android 软件还是网页版的优慕课都是实在难用, 无奈下计划起了这个项目 \ No newline at end of file diff --git a/umooc_client.py b/umooc_client.py new file mode 100644 index 0000000..c5b6754 --- /dev/null +++ b/umooc_client.py @@ -0,0 +1,41 @@ +""" +A client that simulates the desktop device to communicate with umooc server +""" + +import requests +import time + + +class LoginError(BaseException): + def __init__(self, ErrorInfo): + super().__init__(self) + self.errorinfo = ErrorInfo + + def __str__(self): + return self.errorinfo + + +class UmoocClient(object): + def __init__(self): + self.session = '' + + def login(self, username, password): + resp = requests.post('http://eol.ctbu.edu.cn/meol/loginCheck.do', + headers={'Cache-Control': 'max-age=0', + 'Upgrade-Insecure-Requests': '1', + 'Origin': 'http://eol.ctbu.edu.cn', + 'Content-Type': 'application/x-www-form-urlencoded', + 'User-Agent': 'yomooc', + 'Referer': 'http://eol.ctbu.edu.cn/meol/common/security/login.jsp?enterLid=46445', + 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7' + }, + data=f'logintoken={str(time.time()).replace(".", "")[:-4]}' + f'&enterLid=46445' + f'&IPT_LOGINUSERNAME={username}' + f'&IPT_LOGINPASSWORD={password}', + allow_redirects=False, + proxies={'http': 'http://127.0.0.1:54385'}) + if resp.status_code == 302: + self.session = resp.cookies['JSESSIONID'] + else: + raise LoginError('Fail to get session')