Skip to content

Commit

Permalink
Fix for question data not loading bug.
Browse files Browse the repository at this point in the history
Question Data is now loading on frontend. Changed python file
location for data.json to relative path.
  • Loading branch information
Liam Pridgeon committed Feb 27, 2018
1 parent d9a6d24 commit a3f4bc9
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 46 deletions.
Empty file modified arduino/matrix/matrix.ino
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions data.json
Original file line number Original file line Diff line number Diff line change
@@ -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 changes: 12 additions & 13 deletions main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ app.get('/test.html', function(req, res){
res.sendFile(__dirname + '/static/index2.html'); 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){ app.get('/socket.io.js', function(req, res){
res.sendFile(__dirname + '/static/socket.io.js'); res.sendFile(__dirname + '/static/socket.io.js');
Expand Down Expand Up @@ -188,22 +191,18 @@ function getQuestions(){
cmd.stdout.on('data', function(output){ cmd.stdout.on('data', function(output){
console.log(output); console.log(output);
question_data = JSON.parse(output); question_data = JSON.parse(output);

}); });
} }


function sendQuestion(socket){ function sendQuestion(socket){
try { var cmd = process.spawn("python", [questions_file]);
var cmd = process.spawn("python", [questions_file]); console.log("Spawning questions python file process.");

cmd.stdout.on('data', function(output){
cmd.stdout.on('data', function(output){ console.log(output);
console.log(output); question_data = JSON.parse(output).results;
question_data = JSON.parse(output); socket.emit('question', question_data[0]);
socket.emit('question', question_data['results'][0]); });

});
} catch (err){
getQuestions();
}
} }


// Scoring // Scoring
Expand Down Expand Up @@ -263,4 +262,4 @@ function waitForPress(socket){


// NOTE: Could move all game logic to backend - this would then only allow one instance // 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
2 changes: 1 addition & 1 deletion python/api.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
url = urllib.urlopen("https://opentdb.com/api.php?amount=10&type=boolean"); url = urllib.urlopen("https://opentdb.com/api.php?amount=10&type=boolean");
question = json.loads(url.read().decode()); question = json.loads(url.read().decode());


open('../python/data.json', 'w').close(); open('data.json', 'w').close();


with open('data.json', 'w') as outfile: with open('data.json', 'w') as outfile:
json.dump(question, outfile); json.dump(question, outfile);
Expand Down
Empty file modified python/data.json
100644 → 100755
Empty file.
Loading

0 comments on commit a3f4bc9

Please sign in to comment.