Add project files.
This commit is contained in:
28
TriviaBot/CSV/LICENSE
Normal file
28
TriviaBot/CSV/LICENSE
Normal file
@ -0,0 +1,28 @@
|
||||
Copyright (c) 2015, ben-strasser
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of fast-cpp-csv-parser nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
67
TriviaBot/CSV/LoadDB.cpp
Normal file
67
TriviaBot/CSV/LoadDB.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include <stdio.h>
|
||||
#include <sqlite3.h>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "csv.h"
|
||||
|
||||
/**
|
||||
/ Takes the questions stored in the CSV downloaded from https://www.reddit.com/r/trivia/comments/3wzpvt/free_database_of_50000_trivia_questions/
|
||||
/ Questions are stored in a weird format, which makes it a lot harder.
|
||||
/ Hideous code, but only needs to be run one time.
|
||||
/
|
||||
**/
|
||||
|
||||
static int callback(void *x, int argc, char **argv, char **azColName) {
|
||||
int i;
|
||||
for (i = 0; i<argc; i++) {
|
||||
std::cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
sqlite3 *db;
|
||||
char *zErrMsg = 0;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_open("test.db", &db);
|
||||
|
||||
if (rc) {
|
||||
std::cerr << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
|
||||
return(0);
|
||||
}
|
||||
else {
|
||||
std::cout << "Opened database successfully" << std::endl;
|
||||
}
|
||||
|
||||
io::CSVReader<9, io::trim_chars<' ', '\t'>, io::double_quote_escape<',', '"'>> in("trivia.csv");
|
||||
in.read_header(io::ignore_extra_column, "Category", "Question", "Answer", "Category1", "Question1", "Answer1", "Category2", "Question2", "Answer2");
|
||||
std::string c0, q0, a0, c1, q1, a1, c2, q2, a2;
|
||||
int row = 0;
|
||||
sqlite3_stmt *insertThreeQuestions;
|
||||
std::string sql;
|
||||
while (in.read_row(c0, q0, a0, c1, q1, a1, c2, q2, a2)) {
|
||||
sql = "INSERT INTO Questions (Category, Question, Answer) VALUES (?1, ?2, ?3), (?4, ?5, ?6), (?7, ?8, ?9);";
|
||||
sqlite3_prepare_v2(db, sql.c_str(), -1, &insertThreeQuestions, NULL);
|
||||
sqlite3_bind_text(insertThreeQuestions, 1, c0.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 2, q0.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 3, a0.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 4, c1.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 5, q1.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 6, a1.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 7, c2.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 8, q2.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
sqlite3_bind_text(insertThreeQuestions, 9, a2.c_str(), -1, ((sqlite3_destructor_type)-1));
|
||||
|
||||
int result = sqlite3_step(insertThreeQuestions);
|
||||
std::cout << result << " ";
|
||||
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
sqlite3_close(db);
|
||||
|
||||
std::getchar();
|
||||
return 0;
|
||||
}
|
1258
TriviaBot/CSV/csv.h
Normal file
1258
TriviaBot/CSV/csv.h
Normal file
File diff suppressed because it is too large
Load Diff
15236
TriviaBot/CSV/trivia.csv
Normal file
15236
TriviaBot/CSV/trivia.csv
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user