-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathdata.py
95 lines (90 loc) · 3.42 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
import requests
API_URL = "https://opentdb.com/api.php"
PARAMS = {
"amount": 12,
"type": "boolean",
"category": 18
}
def load_data():
"""Loads the data from the API, returns a LIST."""
response = requests.get(API_URL, params=PARAMS)
response.raise_for_status()
response_json = response.json()
if response_json["response_code"] == 0:
return response.json()["results"]
# if there's an issue, use the offline data instead
return offline_data
# quiz data from Day 17, to have an offline back-up
offline_data = [
{"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": "easy",
"question": "The logo for Snapchat is a Bell.",
"correct_answer": "False",
"incorrect_answers": ["True"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "Pointers were not used in the original C programming language; they were added later on in C++.",
"correct_answer": "False",
"incorrect_answers": ["True"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "RAM stands for Random Access Memory.",
"correct_answer": "True",
"incorrect_answers": ["False"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "Ada Lovelace is often considered the first computer programmer.",
"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": "easy",
"question": "Time on Computers is measured via the EPOX System.",
"correct_answer": "False",
"incorrect_answers": ["True"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "The Windows 7 operating system has six main editions.",
"correct_answer": "True",
"incorrect_answers": ["False"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "The NVidia GTX 1080 gets its name because it can only render at a 1920x1080 screen resolution.",
"correct_answer": "False", "incorrect_answers": ["True"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "Linux was first created as an alternative to Windows XP.",
"correct_answer": "False",
"incorrect_answers": ["True"]},
{"category": "Science: Computers",
"type": "boolean",
"difficulty": "easy",
"question": "The Python programming language gets its name from the British comedy group \"Monty Python.\"",
"correct_answer": "True",
"incorrect_answers": ["False"]}
]