From 6eed1dbeca9178f4d6b22b662c63e3bf81186ee1 Mon Sep 17 00:00:00 2001 From: panghaibin Date: Sat, 14 May 2022 00:25:11 +0800 Subject: [PATCH 1/6] gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b6c878f..d9bd8ee 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,5 @@ dmypy.json # custom cookies.json -history.json \ No newline at end of file +history.json +.idea/ \ No newline at end of file From d2fd9debef7a2cd048e4089b19c8731d5f0d4272 Mon Sep 17 00:00:00 2001 From: panghaibin Date: Sat, 14 May 2022 01:37:16 +0800 Subject: [PATCH 2/6] add chaoxing drive --- CDNDrive/drivers/ChaoXingApi.py | 76 +++++++++++++++++++++++++++++++++ CDNDrive/drivers/__init__.py | 5 ++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 CDNDrive/drivers/ChaoXingApi.py diff --git a/CDNDrive/drivers/ChaoXingApi.py b/CDNDrive/drivers/ChaoXingApi.py new file mode 100644 index 0000000..51faf6a --- /dev/null +++ b/CDNDrive/drivers/ChaoXingApi.py @@ -0,0 +1,76 @@ +# coding: utf-8 +import re +from CDNDrive.util import * +from .BaseApi import BaseApi + + +class ChaoXingApi(BaseApi): + headers = { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/84.0.4147.125 Safari/537.36', + 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', + 'X-Requested-With': 'XMLHttpRequest', + } + default_url = lambda self, obj_id: f"https://cs-ans.chaoxing.com/download/{obj_id}" + extract_obj_id = lambda self, s: re.findall(r"[a-fA-F0-9]{32}", s)[0] + get_cookies = lambda self: self.cookies + + def __init__(self): + super().__init__() + self.cookies = load_cookies('chaoxing') + + def meta2real(self, url): + if re.match(r"^cxdrive://[a-fA-F0-9]{32}$", url): + return self.default_url(self.extract_obj_id(url)) + else: + return None + + def real2meta(self, url): + if re.match(r"^https?://.*?\.chaoxing\.com/download/[a-fA-F0-9]{32}$", url): + return "cxdrive://" + self.extract_obj_id(url) + else: + return None + + def set_cookies(self, cookie_str): + self.cookies = parse_cookies(cookie_str) + save_cookies('chaoxing', self.cookies) + + def login(self, username, password): + headers = ChaoXingApi.headers.copy() + login_api = "https://passport2.chaoxing.com/api/login" + params = { + "name": username, + "pwd": password, + "verify": "0", + "schoolid": '' + } + resp = request_retry( + "get", login_api, params=params, + headers=headers, + cookies=self.cookies + ) + if resp.status_code == 403: + result = f"{username}登录得到403,登录请求被拒绝" + return {'code': 114514, 'message': result} + + data = json.loads(resp.text) + if not data['result']: + result = f'{username}登录失败' + return {'code': 114514, 'message': result} + + self.cookies = resp.cookies.get_dict() + save_cookies('chaoxing', self.cookies) + return {'code': 0, 'message': '登录成功'} + + def get_user_info(self, fmt=True): + headers = ChaoXingApi.headers.copy() + check_url = 'http://mooc1-1.chaoxing.com/api/workTestPendingNew' + resp = request_retry( + "get", check_url, + headers=headers, + cookies=self.cookies + ) + if '登录' in resp.text: + return '用户未登录' + else: + return '用户已登录' diff --git a/CDNDrive/drivers/__init__.py b/CDNDrive/drivers/__init__.py index 041e042..a78e299 100644 --- a/CDNDrive/drivers/__init__.py +++ b/CDNDrive/drivers/__init__.py @@ -9,6 +9,7 @@ from .OscApi import OscApi from .SogouApi import SogouApi from .AutoHomeApi import AutoHomeApi +from .ChaoXingApi import ChaoXingApi drivers = { 'bili': BiliApi(), @@ -22,6 +23,7 @@ 'osc': OscApi(), 'sogou': SogouApi(), 'autohome': AutoHomeApi(), + 'chaoxing': ChaoXingApi(), } prefixes = { @@ -38,4 +40,5 @@ 'osdrive': 'osc', 'sgdrive': 'sogou', 'ahdrive': 'autohome', -} \ No newline at end of file + 'cxdrive': 'chaoxing', +} From ec2a0117a5dfb85f820abc0458fb793bbbbb7281 Mon Sep 17 00:00:00 2001 From: panghaibin Date: Sat, 14 May 2022 01:54:19 +0800 Subject: [PATCH 3/6] chaoxing get_user_info --- CDNDrive/drivers/ChaoXingApi.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CDNDrive/drivers/ChaoXingApi.py b/CDNDrive/drivers/ChaoXingApi.py index 51faf6a..e0d31d1 100644 --- a/CDNDrive/drivers/ChaoXingApi.py +++ b/CDNDrive/drivers/ChaoXingApi.py @@ -73,4 +73,15 @@ def get_user_info(self, fmt=True): if '登录' in resp.text: return '用户未登录' else: - return '用户已登录' + info_url = 'http://passport2.chaoxing.com/mooc/accountManage' + resp = request_retry( + "get", info_url, + headers=headers, + cookies=self.cookies + ) + name = re.findall(r"messageName\">(.*?)(.*?) Date: Sat, 14 May 2022 03:29:28 +0800 Subject: [PATCH 4/6] chaoxing img_upload --- CDNDrive/drivers/ChaoXingApi.py | 34 ++++++++++++++++++++++++++++----- CDNDrive/encoders/__init__.py | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CDNDrive/drivers/ChaoXingApi.py b/CDNDrive/drivers/ChaoXingApi.py index e0d31d1..0d282c2 100644 --- a/CDNDrive/drivers/ChaoXingApi.py +++ b/CDNDrive/drivers/ChaoXingApi.py @@ -7,11 +7,9 @@ class ChaoXingApi(BaseApi): headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' - 'Chrome/84.0.4147.125 Safari/537.36', - 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', - 'X-Requested-With': 'XMLHttpRequest', + 'Chrome/84.0.4147.125 Safari/537.36' } - default_url = lambda self, obj_id: f"https://cs-ans.chaoxing.com/download/{obj_id}" + default_url = lambda self, obj_id: f"http://p.ananas.chaoxing.com/star3/origin/{obj_id}.png" extract_obj_id = lambda self, s: re.findall(r"[a-fA-F0-9]{32}", s)[0] get_cookies = lambda self: self.cookies @@ -26,7 +24,7 @@ def meta2real(self, url): return None def real2meta(self, url): - if re.match(r"^https?://.*?\.chaoxing\.com/download/[a-fA-F0-9]{32}$", url): + if re.match(r"^http://p.ananas.chaoxing.com/star3/origin/[a-fA-F0-9]{32}.png$", url): return "cxdrive://" + self.extract_obj_id(url) else: return None @@ -85,3 +83,29 @@ def get_user_info(self, fmt=True): return f"姓名:{name},手机号:{phone}" else: return dict(name=name, phone=phone) + + # def _get_course(self): + # headers = ChaoXingApi.headers.copy() + # course_url = 'https://mooc2-ans.chaoxing.com/visit/courses/list' + + def image_upload(self, img): + headers = ChaoXingApi.headers.copy() + upload_url = 'https://notice.chaoxing.com/pc/files/uploadNoticeFile' + files = { + 'attrFile': (f"{int(time.time() * 1000)}.png", img) + } + try: + resp = request_retry( + "POST", upload_url, + files=files, + headers=headers, + cookies=self.cookies + ) + data = json.loads(resp.text) + if data['status']: + img_url = self.default_url(data['att_file']['att_clouddisk']['fileId']) + return {'code': 0, 'data': img_url} + else: + return None + except Exception as e: + return {'code': 114514, 'message': str(e)} diff --git a/CDNDrive/encoders/__init__.py b/CDNDrive/encoders/__init__.py index f0e025c..0eac217 100644 --- a/CDNDrive/encoders/__init__.py +++ b/CDNDrive/encoders/__init__.py @@ -14,4 +14,5 @@ 'osc': PngEncoder(), 'sogou': PngEncoder(), 'autohome': JpgCatEncoder(), -} \ No newline at end of file + 'chaoxing': PngEncoder(), +} From c43b6b49cda63292eb79a88387947c22d0a69642 Mon Sep 17 00:00:00 2001 From: panghaibin Date: Sat, 14 May 2022 15:27:46 +0800 Subject: [PATCH 5/6] chaoxing img_upload --- CDNDrive/drivers/ChaoXingApi.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CDNDrive/drivers/ChaoXingApi.py b/CDNDrive/drivers/ChaoXingApi.py index 0d282c2..787d7db 100644 --- a/CDNDrive/drivers/ChaoXingApi.py +++ b/CDNDrive/drivers/ChaoXingApi.py @@ -90,7 +90,7 @@ def get_user_info(self, fmt=True): def image_upload(self, img): headers = ChaoXingApi.headers.copy() - upload_url = 'https://notice.chaoxing.com/pc/files/uploadNoticeFile' + upload_url = 'http://notice.chaoxing.com/pc/files/uploadNoticeFile' files = { 'attrFile': (f"{int(time.time() * 1000)}.png", img) } @@ -103,7 +103,8 @@ def image_upload(self, img): ) data = json.loads(resp.text) if data['status']: - img_url = self.default_url(data['att_file']['att_clouddisk']['fileId']) + # img_url = self.default_url(data['att_file']['att_clouddisk']['fileId']) + img_url = data['url'].split('?')[0] return {'code': 0, 'data': img_url} else: return None From e5ca6de88d7abc04886782fd6b2df4373b1b9e37 Mon Sep 17 00:00:00 2001 From: panghaibin Date: Sat, 14 May 2022 17:33:30 +0800 Subject: [PATCH 6/6] version `2022.5.14.0` --- CDNDrive/__init__.py | 2 +- history.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CDNDrive/__init__.py b/CDNDrive/__init__.py index 1a94007..136aacf 100644 --- a/CDNDrive/__init__.py +++ b/CDNDrive/__init__.py @@ -7,4 +7,4 @@ __author__ = "ApacheCN" __email__ = "apachecn@163.com" __license__ = "SATA" -__version__ = "2022.3.20.0" +__version__ = "2022.5.14.0" diff --git a/history.md b/history.md index 53e6d9c..4114804 100644 --- a/history.md +++ b/history.md @@ -1,5 +1,9 @@ # 历史记录 +v2022.5.14.0 + ++ 添加超星学习通图床 + v2022.3.20.0 + 优化历史记录储存方式,使其更稳定