2022-08-10 15:12:43 +00:00
|
|
|
|
import asyncio
|
|
|
|
|
from typing import Coroutine, Optional
|
|
|
|
|
from httpx import AsyncClient, Cookies
|
|
|
|
|
|
|
|
|
|
from cqwu.methods import Methods
|
|
|
|
|
from cqwu.types import User
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Client(Methods):
|
|
|
|
|
"""CQWU main client."""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
username: int = None,
|
|
|
|
|
password: str = None,
|
|
|
|
|
cookie: str = None,
|
|
|
|
|
cookie_file_path: str = "cookie.txt",
|
2023-10-17 13:54:16 +00:00
|
|
|
|
timeout: int = 60,
|
2022-08-10 15:12:43 +00:00
|
|
|
|
):
|
|
|
|
|
self.username = username
|
|
|
|
|
self.password = password
|
|
|
|
|
self.cookie = cookie
|
|
|
|
|
self.cookie_file_path = cookie_file_path
|
2023-03-15 09:31:36 +00:00
|
|
|
|
self.host = "http://ehall.cqwu.edu.cn"
|
2023-09-10 15:01:55 +00:00
|
|
|
|
self.auth_host = "https://authserver.cqwu.edu.cn"
|
2023-03-15 09:31:36 +00:00
|
|
|
|
self.web_ehall_path = ""
|
2022-08-10 15:12:43 +00:00
|
|
|
|
self.cookies = Cookies()
|
2023-03-23 14:31:05 +00:00
|
|
|
|
self.request = AsyncClient(timeout=timeout)
|
2022-08-10 15:12:43 +00:00
|
|
|
|
self.loop = asyncio.get_event_loop()
|
|
|
|
|
self.me: Optional[User] = None
|
2023-03-15 09:31:36 +00:00
|
|
|
|
self._use_password_login = False
|
2023-08-15 07:40:26 +00:00
|
|
|
|
self.xue_nian = 2023
|
2023-06-01 09:03:36 +00:00
|
|
|
|
""" 学年 """
|
2024-02-20 11:19:53 +00:00
|
|
|
|
self.xue_qi = 1
|
2023-06-01 09:03:36 +00:00
|
|
|
|
""" 学期,0 为第一学期,1 为第二学期 """
|
2023-08-15 07:40:26 +00:00
|
|
|
|
self._pay_x_token = ""
|
2022-08-10 15:12:43 +00:00
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_input(word: str = "", is_int: bool = False):
|
|
|
|
|
while True:
|
|
|
|
|
value = input(f"请输入{word}:")
|
|
|
|
|
if not value:
|
|
|
|
|
continue
|
|
|
|
|
if is_int:
|
|
|
|
|
try:
|
|
|
|
|
value = int(value)
|
|
|
|
|
except ValueError:
|
|
|
|
|
continue
|
|
|
|
|
confirm = (input(f'确认是 "{value}" 吗?(y/N): ')).lower()
|
|
|
|
|
if confirm == "y":
|
|
|
|
|
break
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def sync(self, coroutine: Coroutine):
|
|
|
|
|
"""
|
|
|
|
|
同步执行异步函数
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
coroutine (Coroutine): 异步函数
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
该异步函数的返回值
|
|
|
|
|
"""
|
|
|
|
|
return self.loop.run_until_complete(coroutine)
|