refactor: 改善错误信息的显示方式

master
Mufanc 3 years ago
parent 67ae87f319
commit 703266fd1b

@ -1,11 +1,13 @@
import re
import sys
import asyncio
import json
import re
import traceback
import urllib.parse as parser
import httpx
import asyncio
import websockets
import urllib.parse as parser
from loguru import logger
from configs import configs
@ -45,8 +47,7 @@ class Browser(object):
logger.info('[账号校验] | 校验通过')
return True
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[账号校验] | 账号校验出错:{exceptionInformation}')
logger.warning(f'[账号校验] | 账号校验出错:\n{traceback.format_exc()}')
async def wait_for_page(self, regexp): # 等待符合条件的页面出现
async with httpx.AsyncClient() as client:

@ -1,7 +1,8 @@
import sys
import traceback
from os import path
import cv2
import numpy as np
from os import path
from loguru import logger
from numpy import average, dot, linalg
@ -21,8 +22,7 @@ def similarity(img_1, img_2):
a_norm, b_norm = norms
return dot(a / a_norm, b / b_norm)
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[验证码识别] | 运算出错:{exceptionInformation}')
logger.warning(f'[验证码识别] | 运算出错:\n{traceback.format_exc()}')
def recognize(img_content: bytes):
@ -40,5 +40,4 @@ def recognize(img_content: bytes):
logger.info(f'[验证码识别] | 识别结果:{code}')
return code
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[验证码识别] | 识别出错:{exceptionInformation}')
logger.warning(f'[验证码识别] | 识别出错:\n{traceback.format_exc()}')

@ -1,8 +1,10 @@
import sys
import json
import httpx
import traceback
from hashlib import md5
import httpx
from loguru import logger
from .captcha import recognize
@ -19,8 +21,7 @@ class Tree: # 任务树
for ch in self.child:
ch.sort()
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[构建任务树] | 排序出错:{exceptionInformation}')
logger.warning(f'[构建任务树] | 排序出错:\n{traceback.format_exc()}')
class Spider(httpx.AsyncClient):
@ -58,8 +59,7 @@ class Spider(httpx.AsyncClient):
logger.success('[登录] | 登录成功')
return info
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[登录] | 登录出错:{exceptionInformation}')
logger.warning(f'[登录] | 登录出错:\n{traceback.format_exc()}')
async def get_courses(self): # 获取课程列表
try:
@ -75,8 +75,7 @@ class Spider(httpx.AsyncClient):
logger.success('[获取课程列表] | 获取课程列表成功')
return courses
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[获取课程列表] | 获取课程列表出错:{exceptionInformation}')
logger.warning(f'[获取课程列表] | 获取课程列表出错:\n{traceback.format_exc()}')
async def get_books(self, course_id): # 获取某课程的书籍列表
try:
@ -95,8 +94,7 @@ class Spider(httpx.AsyncClient):
)).json()['data']
return books
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[获取书籍列表] | 获取书籍列表出错:{exceptionInformation}')
logger.warning(f'[获取书籍列表] | 获取书籍列表出错:\n{traceback.format_exc()}')
async def get_tasks(self, book_id, book_type, course_id): # 获取某书籍的任务树
try:
@ -133,8 +131,7 @@ class Spider(httpx.AsyncClient):
logger.success('[获取任务列表] | 获取任务列表完成')
return root
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[获取任务列表] | 获取任务列表出错:{exceptionInformation}')
logger.warning(f'[获取任务列表] | 获取任务列表出错:\n{traceback.format_exc()}')
async def get_paper(self, paper_id): # 获取任务点信息(包括题目和答案)
try:
@ -165,8 +162,7 @@ class Spider(httpx.AsyncClient):
logger.success('[获取任务点] | 获取任务点信息完成')
return paper_info
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[获取任务点] | 获取任务点出错:{exceptionInformation}')
logger.warning(f'[获取任务点] | 获取任务点出错:\n{traceback.format_exc()}')
async def user_info(self):
try:
@ -175,8 +171,7 @@ class Spider(httpx.AsyncClient):
logger.success('[获取用户信息] | 获取用户信息完成')
return info
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[获取用户信息] | 获取用户信息出错:{exceptionInformation}')
logger.warning(f'[获取用户信息] | 获取用户信息出错:\n{traceback.format_exc()}')
async def book_info(self, book_id):
try:
@ -208,5 +203,4 @@ class Spider(httpx.AsyncClient):
logger.success('[获取书籍信息] | 获取书籍信息完成')
return book_info
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[获取书籍信息] | 获取书籍信息出错:{exceptionInformation}')
logger.warning(f'[获取书籍信息] | 获取书籍信息出错:\n{traceback.format_exc()}')

@ -1,7 +1,9 @@
import sys
from loguru import logger
from bs4 import BeautifulSoup
import traceback
from random import uniform, randint
from bs4 import BeautifulSoup
from loguru import logger
from configs import configs
from .devtools import Browser
from .spider import Spider
@ -31,8 +33,7 @@ async def list_books(detail):
hint = f'{book["bookName"]}'
logger.info(f'[书籍信息] | {hint}')
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[读取信息] | 读取信息出错:{exceptionInformation}')
logger.warning(f'[读取信息] | 读取信息出错:\n{traceback.format_exc()}')
async def _random(spider, paper_id): # 随机的分数和学习时长
@ -67,8 +68,7 @@ async def _random(spider, paper_id): # 随机的分数和学习时长
return int(100 * score / total), time
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[处理随机数据] | 处理随机数据出错:{exceptionInformation}')
logger.warning(f'[处理随机数据] | 处理随机数据出错:\n{traceback.format_exc()}')
async def _flash(course_id, book_id, spider):
@ -99,8 +99,7 @@ async def _flash(course_id, book_id, spider):
root = await spider.get_tasks(book_id, book_type, course_id)
await dfs(root)
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[刷任务点] | 刷任务点出错:{exceptionInformation}')
logger.warning(f'[刷任务点] | 刷任务点出错:\n{traceback.format_exc()}')
async def flash_by_id(identity):

Loading…
Cancel
Save