qbreader.types module

Types and classes used by the library.

class qbreader.types.Tossup(question: str, question_sanitized: str, answer: str, answer_sanitized: str, difficulty: Difficulty, category: Category, subcategory: Subcategory, packet: PacketMetadata, set: SetMetadata, number: int)

Bases: object

Tossup class.

classmethod from_json(json: dict[str, Any]) Self

Create a Tossup from a JSON object.

See https://www.qbreader.org/api-docs/schemas#tossups for schema.

check_answer_sync(givenAnswer: str) AnswerJudgement

Check whether an answer is correct.

async check_answer_async(givenAnswer: str, session: ClientSession | None = None) AnswerJudgement

Asynchronously check whether an answer is correct.

class qbreader.types.Bonus(leadin: str, leadin_sanitized: str, parts: Sequence[str], parts_sanitized: Sequence[str], answers: Sequence[str], answers_sanitized: Sequence[str], difficulty: Difficulty, category: Category, subcategory: Subcategory, set: SetMetadata, packet: PacketMetadata, number: int, values: Sequence[int] | None = None, difficultyModifiers: Sequence[DifficultyModifier] | None = None)

Bases: object

Bonus class.

classmethod from_json(json: dict[str, Any]) Self

Create a Bonus from a JSON object.

See https://www.qbreader.org/api-docs/schemas#bonus for schema.

check_answer_sync(part: int, givenAnswer: str) AnswerJudgement

Check whether an answer is correct.

async check_answer_async(part: int, givenAnswer: str, session: ClientSession) AnswerJudgement

Asynchronously check whether an answer is correct.

class qbreader.types.Packet(tossups: Sequence[Tossup], bonuses: Sequence[Bonus], number: int | None = None, name: str | None = None, year: int | None = None)

Bases: object

Class for packets in sets.

classmethod from_json(json: dict[str, Any], number: int | None = None) Self

Create a Packet from a JSON object.

See https://www.qbreader.org/api-docs/packet#returns for schema.

paired_questions() zip[tuple[Tossup, Bonus]]

Yield pairs of tossups and bonuses.

class qbreader.types.QueryResponse(tossups: Sequence[Tossup], bonuses: Sequence[Bonus], tossups_found: int, bonuses_found: int, query_string: str)

Bases: object

Class for responses to api/query requests.

classmethod from_json(json: dict[str, Any]) Self

Create a QueryResponse from a JSON object.

See https://www.qbreader.org/api-docs/query#returns for schema.

class qbreader.types.AnswerJudgement(directive: Directive, directed_prompt: str | None = None)

Bases: object

A judgement given by api/check-answer.

correct() bool

Return whether the answer was correct.

classmethod from_json(json: dict[str, Any]) Self

Create an AnswerJudgement from a JSON object.

See https://www.qbreader.org/api-docs/check-answer#returns for schema.

classmethod check_answer_sync(answerline: str, givenAnswer: str) Self

Create an AnswerJudgement given an answerline and an answer.

Original API doc at https://www.qbreader.org/api-docs/check-answer.

Parameters:
  • answerline (str) – The answerline to check against. Preferably including the HTML tags <b> and <u>, if they are present.

  • givenAnswer (str) – The answer to check.

async classmethod check_answer_async(answerline: str, givenAnswer: str, session: ClientSession | None = None) Self

Asynchronously create an AnswerJudgement given an answerline and an answer.

Original API doc at https://www.qbreader.org/api-docs/check-answer.

Parameters:
  • answerline (str) – The answerline to check against. Preferably including the HTML tags <b> and <u>, if they are present.

  • givenAnswer (str) – The answer to check.

  • session (aiohttp.ClientSession) – The aiohttp session to use for the request.

class qbreader.types.Category(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

Question category enum.

LITERATURE = 'Literature'
HISTORY = 'History'
SCIENCE = 'Science'
FINE_ARTS = 'Fine Arts'
RELIGION = 'Religion'
MYTHOLOGY = 'Mythology'
PHILOSOPHY = 'Philosophy'
SOCIAL_SCIENCE = 'Social Science'
CURRENT_EVENTS = 'Current Events'
GEOGRAPHY = 'Geography'
OTHER_ACADEMIC = 'Other Academic'
TRASH = 'Trash'
class qbreader.types.Subcategory(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

Question subcategory enum.

LITERATURE = 'Literature'
HISTORY = 'History'
SCIENCE = 'Science'
FINE_ARTS = 'Fine Arts'
RELIGION = 'Religion'
MYTHOLOGY = 'Mythology'
PHILOSOPHY = 'Philosophy'
SOCIAL_SCIENCE = 'Social Science'
CURRENT_EVENTS = 'Current Events'
GEOGRAPHY = 'Geography'
OTHER_ACADEMIC = 'Other Academic'
TRASH = 'Trash'
AMERICAN_LITERATURE = 'American Literature'
BRITISH_LITERATURE = 'British Literature'
CLASSICAL_LITERATURE = 'Classical Literature'
EUROPEAN_LITERATURE = 'European Literature'
WORLD_LITERATURE = 'World Literature'
OTHER_LITERATURE = 'Other Literature'
AMERICAN_HISTORY = 'American History'
ANCIENT_HISTORY = 'Ancient History'
EUROPEAN_HISTORY = 'European History'
WORLD_HISTORY = 'World History'
OTHER_HISTORY = 'Other History'
BIOLOGY = 'Biology'
CHEMISTRY = 'Chemistry'
PHYSICS = 'Physics'
OTHER_SCIENCE = 'Other Science'
VISUAL_FINE_ARTS = 'Visual Fine Arts'
AUDITORY_FINE_ARTS = 'Auditory Fine Arts'
OTHER_FINE_ARTS = 'Other Fine Arts'
class qbreader.types.Difficulty(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

Question difficulty enum.

UNRATED = '0'
MS = '1'
HS_EASY = '2'
HS_REGS = '3'
HS_HARD = '4'
HS_NATS = '5'
ONE_DOT = '6'
TWO_DOT = '7'
THREE_DOT = '8'
FOUR_DOT = '9'
OPEN = '10'
class qbreader.types.Directive(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

Directives given by api/check-answer.

ACCEPT = 'accept'
REJECT = 'reject'
PROMPT = 'prompt'
qbreader.types.QuestionType

Type alias for question types.

alias of Literal[‘tossup’, ‘bonus’, ‘all’] | Type[Tossup] | Type[Bonus]

qbreader.types.SearchType

Type alias for query search types.

alias of Literal[‘question’, ‘answer’, ‘all’]

qbreader.types.ValidDifficulties

Type alias for valid difficulties.

alias of Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’]

qbreader.types.UnnormalizedDifficulty

Type alias for unnormalized difficulties. Union of Difficulty, ValidDifficulties, and collections.abc.Iterable containing either.

alias of Difficulty | Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’] | Iterable[Difficulty | Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’]] | None

qbreader.types.UnnormalizedCategory

Type alias for unnormalized categories. Union of Category, str, and collections.abc.Iterable containing either.

alias of Category | str | Iterable[Category | str] | None

qbreader.types.UnnormalizedSubcategory

Type alias for unnormalized subcategories. Union of Subcategory, str, and collections.abc.Iterable containing either.

alias of Subcategory | str | Iterable[Subcategory | str] | None