面向开放式琐事数据库的python包装器
trivia.p的Python项目详细描述
在琐事.py在
一个易于使用的python api包装器,用于自动处理Open Trivia DB
注意: 每个请求限制1个类别,每个请求最多50个问题
安装
需要Python3.6或更高版本
pip install trivia.py
使用
^{pr2}$参数:
金额(int): 您希望请求的问题数量默认为10
在类别(int): 您希望从中请求的类别(请参阅下表中哪个数字与哪个类别相关),默认为
在None
返回所有类别。在
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 |
难度(str): 问题的难度,可以是
在easy
,medium
,或者{}。默认为 None
返回所有困难。在quizType(str): 问题类型可以是
在multiple
(多选题),或boolean
(真/假问题)。默认为None
返回所有问题类型。在
返回:
返回包含以下键的dict列表
类别(str): 问题来自的类别。在
在类型(str): 问题的类型(多个或布尔型)。在
在难度(str): 这个问题的困难。在
在问题(str): 问题的文本。在
在正确答案(str): 正确答案。在
在回答不正确(list): 所有错误答案的字符串列表。在
在
示例
基本代码示例
fromtriviaimporttriviaimportasyncio#To use outside of an async functionloop=asyncio.get_event_loop()questions=loop.run_until_complete(trivia.question(amount=1,category=2,difficulty='easy',quizType='multiple'))#To use within an aysnc functionasyncdefmain():questions=awaittrivia.question(amount=1,category=2,difficulty='easy',quizType='multiple')
返回的示例
[{'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']}]
- 项目
标签: