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

添加超星学习通图床 #36

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@ dmypy.json

# custom
cookies.json
history.json
history.json
.idea/
2 changes: 1 addition & 1 deletion CDNDrive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
__author__ = "ApacheCN"
__email__ = "apachecn@163.com"
__license__ = "SATA"
__version__ = "2022.3.20.0"
__version__ = "2022.5.14.0"
112 changes: 112 additions & 0 deletions CDNDrive/drivers/ChaoXingApi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 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'
}
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

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"^http://p.ananas.chaoxing.com/star3/origin/[a-fA-F0-9]{32}.png$", 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:
info_url = 'http://passport2.chaoxing.com/mooc/accountManage'
resp = request_retry(
"get", info_url,
headers=headers,
cookies=self.cookies
)
name = re.findall(r"messageName\">(.*?)</", resp.text)[0]
phone = re.findall(r"messagePhone\">(.*?)</", resp.text)[0]
if fmt:
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 = 'http://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'])
img_url = data['url'].split('?')[0]
return {'code': 0, 'data': img_url}
else:
return None
except Exception as e:
return {'code': 114514, 'message': str(e)}
5 changes: 4 additions & 1 deletion CDNDrive/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .OscApi import OscApi
from .SogouApi import SogouApi
from .AutoHomeApi import AutoHomeApi
from .ChaoXingApi import ChaoXingApi

drivers = {
'bili': BiliApi(),
Expand All @@ -22,6 +23,7 @@
'osc': OscApi(),
'sogou': SogouApi(),
'autohome': AutoHomeApi(),
'chaoxing': ChaoXingApi(),
}

prefixes = {
Expand All @@ -38,4 +40,5 @@
'osdrive': 'osc',
'sgdrive': 'sogou',
'ahdrive': 'autohome',
}
'cxdrive': 'chaoxing',
}
3 changes: 2 additions & 1 deletion CDNDrive/encoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
'osc': PngEncoder(),
'sogou': PngEncoder(),
'autohome': JpgCatEncoder(),
}
'chaoxing': PngEncoder(),
}
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 历史记录

v2022.5.14.0

+ 添加超星学习通图床

v2022.3.20.0

+ 优化历史记录储存方式,使其更稳定
Expand Down