Skip to main content

A python wrapper for Open Trivia DB

Project description

trivia.py

An easy to use python api wrapper for Open Trivia DB with autocaching

Note: There is an request limit of 1 category per request and a max of 50 questions per request

Installing

Python 3.6 or higher is required

pip install trivia.py

Usage

question(parameters)

Parameters:

  • amount (int): The amount of questions you wish to request, defaults to 10

  • category (int): The category you wish to request from (refer to table below for which number correlates to which category), defaults to None returning all categories.

Int Category
0 All categories
1 General Knowledge
2 Entertainment: Books
3 Entertainment: Film
4 Entertainment: Music
5 Entertainment: Musicals & Theatres
6 Entertainment: Television
7 Entertainment: Video Games
8 Entertainment: Board Games
9 Science & Nature
10 Science: Computers
11 Science: Mathematics
12 Mythology
13 Sports
14 Geography
15 History
16 Politics
17 Art
18 Celebrities
19 Animals
20 Vehicles
21 Entertainment: Comics
22 Science: Gadgets
23 Entertainment: Japanese Anime & Manga
24 Entertainment: Cartoon & Animations
  • difficulty (str): The difficulty of the questions, can be easy, medium, or hard. Defaults to None returning all difficulties.

  • quizType (str): The type of questions, can be multiple (multiple choice questions), or boolean (true/false questions). Defaults to None returning all questions types.

Return:

Return a list of dicts which contains the keys below

  • category (str): The category the question comes from.

  • type (str): The type of question (multiple, or boolean).

  • difficulty (str): The difficulty of the question.

  • question (str): The text of the question.

  • correct_answer (str): The correct answer.

  • incorrect_answer (list): List of strings of all the incorrect answers.

Examples

Basic code example

from trivia import trivia
import asyncio

#To use outside of an async function
loop = asyncio.get_event_loop()
questions = loop.run_until_complete(trivia.question(amount=1, category=2, difficulty='easy', quizType='multiple'))

#To use within an aysnc function
async def main():
    questions = await trivia.question(amount=1, category=2, difficulty='easy', quizType='multiple')

An example of the return

[{
    'category': 'Entertainment: Books', 
    'type': 'multiple', 
    'difficulty': 'easy', 
    'question': 'What is the title of the first Sherlock Holmes book by Arthur Conan Doyle?',
     'correct_answer': 'A Study in Scarlet', 
     'incorrect_answers': ['The Sign of the Four', 'A Case of Identity', 'The Doings of Raffles Haw']
}]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trivia.py-1.0.8.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trivia.py-1.0.8-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file trivia.py-1.0.8.tar.gz.

File metadata

  • Download URL: trivia.py-1.0.8.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for trivia.py-1.0.8.tar.gz
Algorithm Hash digest
SHA256 9b9065575b6709682bb57888667d68ad1bd13c9eadddb209ce1eceb1c349df8c
MD5 3c84d80ff9da7a04384e6437e89234cd
BLAKE2b-256 5a052150257cdae7758b38882ad1f3a77d3d6afc49ab92fffdb5b274f33fcc7e

See more details on using hashes here.

File details

Details for the file trivia.py-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: trivia.py-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for trivia.py-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8f96d819e3bebb15d150c4180d8f1c1b000ffbe443be85750b4329ce2c1eb3a3
MD5 d78291db1914d79785b08c433776a068
BLAKE2b-256 9d45f44ed1493da142c33b8e790af2636b89ea1369c003cffdb2c6bf94888a3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page