Skip to content

A python2 library for interacting with the Open Trivia Database (openTDB) API

License

Notifications You must be signed in to change notification settings

ianling/opentdb-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opentdb-python

A python2 library for interacting with the Open Trivia Database (openTDB) API

https://opentdb.com/api_config.php

Example Usage

import opentdb

opentdb_session = opentdb.Client()
opentdb_session.getToken()
questions = opentdb_session.getQuestions(amount=5, use_token=True, category=18)

You can retrieve a Dictionary of all the category names and ID numbers via the Client:

categories = opentdb_session.getCategories()
# categories['Science: Computers'] == 18

Once you've retrieved some questions, you can do whatever you'd like with them.

for question in questions:
    print 'Category: %s (ID: %i)' % (question.category, question.getCategoryId())
    print 'Question: %s' % (question)
    print 'Answer : %s' % (question.correct_answer)

The submissions to the Open Trivia DB are usually (always?) in the form of multiple choice questions, so you can also view a List of incorrect answers using question.incorrect_answers.

About

A python2 library for interacting with the Open Trivia Database (openTDB) API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages