Skip to content

Commit

Permalink
Increase the waiting time after connection error;
Browse files Browse the repository at this point in the history
Increase the number of video task threads;
Display better placeholders for in-chapter images;
Fixed crash when attachment has no mid;
  • Loading branch information
chettoy committed May 10, 2022
1 parent f92888a commit c3c8c1a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions fxxkstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
}

G_STRINGS = {
"alt_insertimage": " - [IMG]",
"antispider_verify": "⚠️ Anti-Spider verify",
"correct_answer": "Correct answer: ",
"course_list_title": "Course List",
Expand Down Expand Up @@ -107,6 +108,7 @@
}

G_STRINGS_CN = {
"alt_insertimage": " - [图片]",
"antispider_verify": "⚠️ 反蜘蛛验证",
"correct_answer": "正确答案: ",
"course_list_title": "课程列表",
Expand Down Expand Up @@ -326,7 +328,7 @@ def url_302(self, oldUrl: str, additional_headers: dict = {}) -> str:
raise MyError(0, G_STRINGS['antispider_verify'])
return new_url

def request(self, url: str, additional_headers: dict = {}, data=None, method="GET", retry=2) -> requests.Response:
def request(self, url: str, additional_headers: dict = {}, data=None, method="GET", retry=3) -> requests.Response:
headers = self.agent.build_headers_based_on(additional_headers)
rsp = None
while retry >= 0:
Expand All @@ -342,7 +344,7 @@ def request(self, url: str, additional_headers: dict = {}, data=None, method="GE
retry -= 1
tag = "[{}] ".format(time.asctime(time.localtime(time.time())))
print(tag, err)
time.sleep(5)
time.sleep(10)

if rsp.status_code == 200:
# print(rsp.text)
Expand Down Expand Up @@ -1256,7 +1258,7 @@ def __init__(self, fxxkstar: FxxkStar, attachment_item: dict, card_info: dict, c
self.course_id: str = course_id
self.clazz_id: str = clazz_id
self.chapter_id: str = chapter_id
self.mid: str = attachment_item['mid']
self.mid: str | None = attachment_item.get("mid", None)
self.defaults: dict = self.card_args['defaults']
self.job: bool = attachment_item.get("job", False)
self.module_type: str = attachment_item.get("type")
Expand Down Expand Up @@ -2390,14 +2392,18 @@ def _info(work_id: str, card_url: str):
def save(fxxkstar: FxxkStar, questions: List[dict], work_id: str, card_url: str) -> None:
data = []
for item in questions:
topic = item.get('topic')
r_type = WorkModule.chaoxing_type_to_banktype(item.get('type'))
correct = item.get('correct', None)
wrong = item.get('wrong', None)
assert isinstance(topic, str)
assert isinstance(r_type, int)
if not correct and not wrong:
continue

topic = item.get('topic')
r_type = WorkModule.chaoxing_type_to_banktype(item.get('type'))
if r_type == -1:
continue
assert isinstance(topic, str)
assert isinstance(r_type, int)

save_item = {
"topic": topic,
"type": r_type,
Expand All @@ -2410,6 +2416,9 @@ def save(fxxkstar: FxxkStar, questions: List[dict], work_id: str, card_url: str)
del save_item['wrong']
data.append(save_item)

if len(data) == 0:
return

serialized_str: str = urllib.parse.urlencode({
"info": __class__._info(work_id, card_url),
"data": json.dumps(data),
Expand Down Expand Up @@ -2632,6 +2641,8 @@ def medias_deal(self, card_info: dict, course_id: str, clazz_id: str, chapter_id
attachment_property['bookname'])
print("[InsertBook]",
attachment_property['readurl'])
elif module_type == "insertimage":
print(G_STRINGS['alt_insertimage'])
else:
print(module_type)
else:
Expand Down Expand Up @@ -2938,7 +2949,7 @@ def prepare() -> FxxkStar:
helper.choose_course_and_study()

if input(G_STRINGS['input_if_sync_video_progress']) == 'y':
helper.sync_video_progress()
helper.sync_video_progress(5)

except Exception as err:
tag = "[{}] ".format(time.asctime(time.localtime(time.time())))
Expand Down

0 comments on commit c3c8c1a

Please sign in to comment.