client
Client interfaces for the OpenTriviaDB wrapper.
Client
A client for the Open Trivia API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str, optional
|
Your session token. This is not an access token in the traditional sense (and is thus optional), but a token generated by the API in order to track which questions you have received. This is done to prevent duplicate questions. |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
loop |
AbstractEventLoop, optional
|
The event loop the client should use. If you don't provide one, the client will create one. |
session |
ClientSession, optional
|
The AIOHTTP session the client should use. If you don't provide one, the client will create one. |
Source code in opentriviadb/client.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
request_token
async
Request a session token from the API.
While the token is returned from this method, you don't need to do anything extra to allow the client to use the token.
Returns:
Type | Description |
---|---|
str
|
The session token. This is automatically applied to the client, but is returned to allow you to store it for future use. |
Source code in opentriviadb/client.py
reset_token
async
Reset a session token.
This resets the token currently applied to the client. This does not error if no token currently exists, but instead silently does nothing.
Returns:
Type | Description |
---|---|
None
|
Source code in opentriviadb/client.py
round
async
round(amount: int = 10, category: Category | None = None, difficulty: t.Literal[easy, medium, hard] | None = None, type: t.Literal[multiple, boolean] | None = None) -> t.AsyncIterator[Question]
Run a round of trivia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amount |
int, optional
|
The number of questions the round should contain. This cannot be higher than 50, and defaults to 10. |
10
|
category |
Category, optional
|
The category of the questions that should be in the round.
This should be passed as a |
None
|
difficulty |
"easy" or "medium" or "hard", optional
|
The difficulty of questions that should be in the round. If this is not provided, the questions can be of any difficulty. |
None
|
type |
"multiple" or "boolean", optional
|
The type of questions that should be in the round. This can either be multiple choice ("multiple") or true-false ("boolean"). If this is not provided, the questions can be either. |
None
|
Yields:
Type | Description |
---|---|
Question
|
Asynchronously yield questions one by one. |
Raises:
Type | Description |
---|---|
NoResults
|
The API does not have enough questions to satisfy your query. |
InvalidParameter
|
An invalid parameter has been passed. |
TokenNotFound
|
Session token does not exist (session tokens are not required to make requests). |
TokenEmpty
|
The session token needs to be reset (use
|
Example with parameters
Source code in opentriviadb/client.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
teardown
async
Close the AIOHTTP session.
This should be called before closing your program. If you use the client via the context manager, this is called automatically.
Returns:
Type | Description |
---|---|
None
|