Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大神们谁有最新.db题库呀,跪求 #94

Open
shan5463 opened this issue Aug 27, 2020 · 6 comments
Open

大神们谁有最新.db题库呀,跪求 #94

shan5463 opened this issue Aug 27, 2020 · 6 comments

Comments

@shan5463
Copy link

No description provided.

@shan5463 shan5463 changed the title 大神们谁有最新 大神们谁有最新.db题库呀,跪求 Aug 27, 2020
@Dr-Octopus-dev
Copy link

Dr-Octopus-dev commented Aug 30, 2020

按照lolisaikou的方法,可以实现更新题库

@shan5463
Copy link
Author

shan5463 commented Sep 2, 2020

按照lolisaikou的方法,可以实现更新题库

可以放张截图吗,看看你怎么改的,我的报错

@Dr-Octopus-dev
Copy link

按照lolisaikou的方法,可以实现更新题库

可以放张截图吗,看看你怎么改的,我的报错

还是你截图吧,看看你报的什么错

@shan5463 shan5463 closed this as completed Sep 3, 2020
@shan5463 shan5463 reopened this Sep 3, 2020
@shan5463
Copy link
Author

shan5463 commented Sep 3, 2020

按照lolisaikou的方法,可以实现更新题库

可以放张截图吗,看看你怎么改的,我的报错

还是你截图吧,看看你报的什么错

微信图片_20200903192028

@lolisaikou
Copy link

可以不用jsoup来解析html
CreateAndInsertupdateTikunet这两个函数换成下面的

/**
 * @description: 更新数据库tikuNet表
 * @param  {} liArray li列表,包含题目和答案
 */
function CreateAndInsert(liArray) {

    var dbName = "tiku.db";
    //文件路径
    var path = files.path(dbName);
    //确保文件存在
    if (!files.exists(path)) {
        files.createWithDirs(path);
    }
    //创建或打开数据库
    var db = SQLiteDatabase.openOrCreateDatabase(path, null);
    var createTable = "\
    CREATE TABLE IF NOT EXISTS tikuNet(\
    question CHAR(253),\
    answer CHAR(100)\
    );";
    var cleanTable = "DELETE FROM tikuNet";
    db.execSQL(createTable);
    db.execSQL(cleanTable);
    log("创建打开清空表tikuNet!");

    var sql = "INSERT INTO tikuNet (question, answer) VALUES (?, ?)";
    db.beginTransaction();
    var stmt = db.compileStatement(sql);
    for (var li = 0, len = liArray.length; li < len; li++) {
        //log("题目:"+li.text());
        var tiMu = liArray[li].content;
        var daAn = liArray[li].answer;
        log(util.format("题目:%s\n答案:%s"), tiMu, daAn);
        stmt.bindString(1, tiMu);
        stmt.bindString(2, daAn);
        stmt.executeInsert();
        stmt.clearBindings();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();
    return true;
}

下面这个函数里的题库地址是我用jsdelivr加速的

function updateTikunet() {
    log("开始下载题库json数据...");
    var htmlArray = http.get("https://cdn.jsdelivr.net/gh/lolisaikou/tiku-autoupdate/questions.json");
    var liArray = htmlArray.body.json();
    log(util.format("题库下载完毕,题目总数:%s"), liArray.length);
    //执行更新
    log("开始更新数据库...");
    CreateAndInsert(liArray)
    console.log("数据库更新完毕!更新了" + liArray.length + "道题!");
}

然后ui部分加个<button id="update" h="60" text="更新题库" />
最后把这里的注释删掉就行
image

@lolisaikou
Copy link

可以不用jsoup来解析html
CreateAndInsertupdateTikunet这两个函数换成下面的

/**
 * @description: 更新数据库tikuNet表
 * @param  {} liArray li列表,包含题目和答案
 */
function CreateAndInsert(liArray) {

    var dbName = "tiku.db";
    //文件路径
    var path = files.path(dbName);
    //确保文件存在
    if (!files.exists(path)) {
        files.createWithDirs(path);
    }
    //创建或打开数据库
    var db = SQLiteDatabase.openOrCreateDatabase(path, null);
    var createTable = "\
    CREATE TABLE IF NOT EXISTS tikuNet(\
    question CHAR(253),\
    answer CHAR(100)\
    );";
    var cleanTable = "DELETE FROM tikuNet";
    db.execSQL(createTable);
    db.execSQL(cleanTable);
    log("创建打开清空表tikuNet!");

    var sql = "INSERT INTO tikuNet (question, answer) VALUES (?, ?)";
    db.beginTransaction();
    var stmt = db.compileStatement(sql);
    for (var li = 0, len = liArray.length; li < len; li++) {
        //log("题目:"+li.text());
        var tiMu = liArray[li].content;
        var daAn = liArray[li].answer;
        log(util.format("题目:%s\n答案:%s"), tiMu, daAn);
        stmt.bindString(1, tiMu);
        stmt.bindString(2, daAn);
        stmt.executeInsert();
        stmt.clearBindings();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();
    return true;
}

下面这个函数里的题库地址是我用jsdelivr加速的

function updateTikunet() {
    log("开始下载题库json数据...");
    var htmlArray = http.get("https://cdn.jsdelivr.net/gh/lolisaikou/tiku-autoupdate/questions.json");
    var liArray = htmlArray.body.json();
    log(util.format("题库下载完毕,题目总数:%s"), liArray.length);
    //执行更新
    log("开始更新数据库...");
    CreateAndInsert(liArray)
    console.log("数据库更新完毕!更新了" + liArray.length + "道题!");
}

然后ui部分加个<button id="update" h="60" text="更新题库" />
最后把这里的注释删掉就行
image

多谢大神啦,有点复杂。。可以给我邮箱([email protected])发一下改好的.js文件嘛,不胜感激!祝您周末愉快

看我主页,有另一个版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants