-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
132 lines (125 loc) · 3.8 KB
/
data.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
import requests
# To my perspective:
# It is more easily to read, maintain, organized and especially modified the codes,
# So, setting the parameters on the top is crucial.
# (Be aware of the form that you should write in the parameters!)
parameters = {
"amount": 10,
"type": "boolean",
"category": 18
}
response = requests.get(url="https://opentdb.com/api.php",
params=parameters)
response.raise_for_status()
data = response.json()
# print(data)
# print(type(data))
# new_data = data["results"]
question_data = data["results"]
# print(question_data)
# question_data = [
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "The HTML5 standard was published in 2014.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "The first computer bug was formed by faulty wires.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "FLAC stands for 'Free Lossless Audio Condenser'.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "All program codes have to be compiled into an executable file in order to be run. This file can then be executed on any machine.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "Linus Torvalds created Linux and Git.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "The programming language 'Python' is based off a modified version of 'JavaScript'",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "AMD created the first consumer 64-bit processor.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "'HTML' stands for Hypertext Markup Language.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "In most programming languages, the operator ++ is equivalent to the statement '+= 1'.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "hard",
# "question": "The IBM PC used an Intel 8008 microprocessor clocked at 4.77 MHz and 8 kilobytes of memory.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# }
# ]
# print(question_data)
# print(type(question_data))
# print(type(new_data))
# question_data = new_data