forked from alhamilton1111/Capstone2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestURL.py
34 lines (30 loc) · 1.12 KB
/
testURL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pprint as pp
import urllib.request, json
def getQuestions(qty,cate,diffi):
baseUrl = f"https://opentdb.com/api.php?amount={qty}"
specificUrl = f"https://opentdb.com/api.php?amount={qty}&category={cate}&difficulty={diffi}"
shortUrl = f"https://opentdb.com/api.php?amount={qty}&difficulty={diffi}"
with urllib.request.urlopen(specificUrl) as url:
data = json.loads(url.read().decode())
print(data)
return data
def main():
result = getQuestions(10, 13, "medium")
#print(result)
print("###################################")
#print(result['results'])
#print(type(result['results']))
for each in result['results']:
#print(each)
category = each['category']
print(f"Category: {category}")
typeQ = each['type']
print(f"Question Type: {typeQ}")
question = each['question']
print(f"Question: {question}")
answerCorrect = each['correct_answer']
print(f"Correct Answer: {answerCorrect}")
answersWrong = each['incorrect_answers']
print(f"Wrong Answers: {answersWrong}")
print("%%%%%%%%%%%")
main()