参考#

PyLuogu#

A model-based Python implement for Luogu API client

洛谷 API 客户端基于模型的 Python 实现

模型#

class luogu.Paste(id: str)[源代码]#

剪贴板

参数

id (str) – 剪贴板 ID

变量

在 0.1 版更改: 变量 time 的类型自 int 改为 datetime.datetime

delete() str[源代码]#

删除剪贴板

返回

剪贴板 ID

返回类型

str

edit(data: Optional[str] = None, public: Optional[bool] = None)[源代码]#

编辑剪贴板

参数
  • data (str) – 剪贴板内容

  • public (bool) – 是否公开

返回

剪贴板 ID

返回类型

str

classmethod new(data: str, public: Optional[bool] = None) luogu.models.paste.Paste[源代码]#

新建剪贴板

参数
  • data (str) – 剪贴板内容

  • public (bool) – 值为真时表示公开剪贴板,否则表示私有剪贴板

返回类型

Session.Paste

class luogu.Problem(pid: str)[源代码]#

题目

参数

pid (str) – 题目 ID

引发
变量
  • background (str) – 题目背景

  • description (str) – 题目描述

  • input_format (str) – 输入格式

  • output_format (str) – 输出格式

  • samples (list[tuple[str, str]]) – 样例

  • hint (str) – 说明/提示

  • provider (User) – 题目提供者

  • attachments (list[Attachment]) – 附件

  • can_edit (bool) – 可编辑

  • limits (dict[str, list[int]]) – 限制

  • std_code (str) – 标准代码

  • tags (list[int]) – 标签

  • wants_translation (bool) – 需要翻译

  • total_submit (int) – 总提交

  • total_accepted (int) – 总通过

  • flag (int) –

  • pid (str) – 题目 ID

  • title (str) – 题目标题

  • difficulty (int) – 难度

  • full_score (int) – 满分

  • type (str) – 题目类型

class Attachment(downloadLink: str, size: int, uploadTime: int, id: str, filename: str)#

附件

变量
  • download_link (str) – 下载链接

  • size (int) – 大小

  • upload_time (datetime.datetime) – 上传时间

  • id (str) – ID

  • filename (str) – 文件名

在 0.1 版更改: 变量 upload_time 的类型自 int 改为 datetime.datetime

class luogu.User(uid: int | str)[源代码]#

用户

参数

uid (int | str) – 用户 ID

引发

NotFoundHttpException – 用户未找到

变量
  • register_time (datetime.datetime) – 注册时间

  • introduction (str) – 个人介绍

  • prize (list[Prize]) – 获奖信息

  • blog_address (str) – 个人博客地址

  • passed_problem_count (int | None) – 已通过题目数量

  • submitted_problem_count (int | None) – 提交题目数量

  • uid (int) – 用户 ID

  • name (str) – 用户名

  • slogan (str) – 个性签名

  • badge (str | None) – 徽章

  • is_admin (bool) – 是否管理员

  • is_banned (bool) – 是否被封禁

  • color (str) – 颜色

  • ccf_level (int) – CCF 等级

  • following_count (int) – 关注数量

  • follower_count (int) – 粉丝数量

  • ranking (int) – 排名

  • background (str) – 封面

  • is_root (bool | None) – 是否为 root

  • passed_problems (list[Problem] | None) – 已通过的题目

  • submitted_problems (list[Problem] | None) – 尝试过的题目

在 0.1 版更改: 变量 register_time 的类型自 int 改为 datetime.datetime

class Prize(year: int, contestName: str, prize: str)[源代码]#

获奖信息

变量
  • year (int) – 年份

  • contest_name (str) – 竞赛名称

  • prize (str) – 奖项

classmethod search(keyword: str) list[User][源代码]#

根据 UID 或用户名搜索用户

参数

keyword (str) – 搜索关键字

会话#

class luogu.Session(cookies: str | dict[str, str] | None = None)[源代码]#

会话

参数

cookies (str | dict[str, str] | None) – Cookies

变量
class Paste(id: str)[源代码]#
class Problem(pid: str)[源代码]#
class User(uid: int | str)[源代码]#
captcha(show: bool = True) bytes[源代码]#

获取验证码

参数

show (bool) – 值为真时使用 PIL.Image.Image.show() 显示验证码;否则仅返回图片的二进制数据

返回类型

bytes

login(username: str, password: str, captcha: str) dict[str][源代码]#

登录

参数
  • username (str) – 用户名

  • password (str) – 密码

  • captcha (str) – 验证码

返回类型

dict[str]

logout() dict[str, bool][源代码]#

登出

返回类型

dict[str, bool]

异常#

exception luogu.HttpException[源代码]#
exception luogu.AccessDeniedHttpException[源代码]#

403

exception luogu.NotFoundHttpException[源代码]#

404

{
   "code": 404,
   "currentTemplate": "InternalError",
   "currentData": {
         "errorType": "LuoguFramework\\HttpFoundation\\Controller\\Exception\\HttpException\\NotFoundHttpException",
         "errorMessage": "该页面未找到",
         "errorTrace": ""
   },
   "currentTitle": "出错了",
   "currentTheme": null
}