Permalink
Browse files

Fix for question data not loading bug.

Question Data is now loading on frontend. Changed python file
location for data.json to relative path.
  • Loading branch information...
Liam Pridgeon
Liam Pridgeon committed Feb 27, 2018
1 parent d9a6d24 commit a3f4bc928fc9292b26ac36ae7f1a35c9387e75c9
Showing with 423 additions and 46 deletions.
  1. 0 arduino/matrix/matrix.ino
  2. +1 −0 data.json
  3. +12 −13 main.js
  4. +1 −1 python/api.py
  5. 0 python/data.json
  6. +370 −0 static/api_call.js
  7. +39 −32 static/index.html
0 arduino/matrix/matrix.ino 100644 → 100755
No changes.
@@ -0,0 +1 @@
{"response_code": 0, "results": [{"category": "Entertainment: Video Games", "type": "boolean", "question": "Peter Molyneux was the founder of Bullfrog Productions.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Science & Nature", "type": "boolean", "question": "Type 1 diabetes is a result of the liver working improperly.", "difficulty": "medium", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Science: Computers", "type": "boolean", "question": "To bypass US Munitions Export Laws, the creator of the PGP published all the source code in book form. ", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Video Games", "type": "boolean", "question": "Niko Bellic is the protagonist of Grand Theft Auto IV.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Science: Computers", "type": "boolean", "question": ""HTML" stands for Hypertext Markup Language.", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Entertainment: Video Games", "type": "boolean", "question": "In the game "Subnautica", a "Cave Crawler" will attack you.", "difficulty": "medium", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Science: Mathematics", "type": "boolean", "question": "Zero factorial is equal to zero. ", "difficulty": "medium", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Science: Mathematics", "type": "boolean", "question": "In Topology, the complement of an open set is a closed set.", "difficulty": "hard", "correct_answer": "True", "incorrect_answers": ["False"]}, {"category": "Politics", "type": "boolean", "question": "George Clinton, Vice President of the United States (1805-1812), is an ancestor of President Bill Clinton.", "difficulty": "hard", "correct_answer": "False", "incorrect_answers": ["True"]}, {"category": "Entertainment: Video Games", "type": "boolean", "question": "The game "Pocket Morty" has a Morty called "Pocket Mortys Morty"?", "difficulty": "easy", "correct_answer": "True", "incorrect_answers": ["False"]}]}
25 main.js
@@ -28,6 +28,9 @@ app.get('/test.html', function(req, res){
res.sendFile(__dirname + '/static/index2.html');
});
app.get('/api_call.js', function(req, res){
res.sendFile(__dirname + '/static/api_call.js');
});
app.get('/socket.io.js', function(req, res){
res.sendFile(__dirname + '/static/socket.io.js');
@@ -188,22 +191,18 @@ function getQuestions(){
cmd.stdout.on('data', function(output){
console.log(output);
question_data = JSON.parse(output);
});
}
function sendQuestion(socket){
try {
var cmd = process.spawn("python", [questions_file]);
cmd.stdout.on('data', function(output){
console.log(output);
question_data = JSON.parse(output);
socket.emit('question', question_data['results'][0]);
});
} catch (err){
getQuestions();
}
var cmd = process.spawn("python", [questions_file]);
console.log("Spawning questions python file process.");
cmd.stdout.on('data', function(output){
console.log(output);
question_data = JSON.parse(output).results;
socket.emit('question', question_data[0]);
});
}
// Scoring
@@ -263,4 +262,4 @@ function waitForPress(socket){
// NOTE: Could move all game logic to backend - this would then only allow one instance
// TODO: Update the LED and Button GPIO binding values
// TODO: Update the LED and Button GPIO binding values
@@ -9,7 +9,7 @@
url = urllib.urlopen("https://opentdb.com/api.php?amount=10&type=boolean");
question = json.loads(url.read().decode());
open('../python/data.json', 'w').close();
open('data.json', 'w').close();
with open('data.json', 'w') as outfile:
json.dump(question, outfile);
0 python/data.json 100644 → 100755
No changes.
Oops, something went wrong.

0 comments on commit a3f4bc9

Please sign in to comment.