简体   繁体   English

代码未执行完整脚本

[英]Code isn't executing the full script

I wrote some code that checks a list, and checks if each item in the list is present in the other one. 我编写了一些代码来检查一个列表,并检查列表中的每个项目是否在另一个项目中。 If the item isn't found, it adds it to the database. 如果找不到该项目,它将添加到数据库中。

The scanning code is correct (the part that says db.scan) but somewhere towards the end the code isn't going through because its not executing the console.log part (Where it says "Entering journal into database..." title of article " When I execute this code, nothing happens. At least there are no errors... but its not even logging the console.log parts so something is wrong. 扫描代码是正确的(表示db.scan的部分),但由于未执行console.log部分(在其中显示“正在将日记输入数据库...”的标题),因此该代码未通过。文章 “当我执行这个代码,什么都不会发生,至少没有错误...但它甚至没有记录该部分的console.log这样的东西是错误的。

// accessing the database
function DatabaseTime(sourcesDates, timeAdded, links, titles, descriptions) {
    sourcesDates = sourcesDates;
    links = links;
    titles = titles;     //  this will be used to check on our articles
    descriptions = descriptions;

    var autoParams;
    var databaseOperation = function (sourcesDates, timeAdded, links, titles, descriptions) {
        var scanParams = { TableName: "Rnews" }
            // using code to setup for accessing the 2nd list
            db.scan(scanParams, function(err, scanData) {   // scanData = the 2nd list we are going to work with
                var counter = 0;    // just a way to help make my code more accurate as seen later in the loops
                var counter2 = 0;
                // this is the first list iterating on
                for (var i = 0; i < links.length; i++) {
                    counter = 0;
                    // looping through items in second list
                    for (var x = 0; x < scanData.Items.length; x++) {
                        // if article is not in db
                        if (titles[i] !== scanData.Items[x].title) {
                            continue; 
                        } 
                        else if (titles[i] === scanData.Items[x].title) {
                            // intention is to immediately move to the next item in the first list if this block executes
                            console.log("Article found: \"" + titles[i] + "\". Not proceeding anymore with article.");
                            counter++;
                            break;
                        } else {
                            //  if this article isnt found anywhere in the list we are checking on, add to database
                            if (x === scanData.Items.length && counter !== 0) {
                                autoParams = {
                                    TableName: "Rnews",
                                    Item: {
                                        title: titles[i],
                                        source: sourcesDates[i],
                                        url: links[i],
                                        description: descriptions[i],
                                        lastAddOrUpdated: dbTimeStamp,
                                        timePublish: timeAdded[i]
                                    }
                                }
                                console.log("Entering journal to database: " + titles[i]);
                                db.put(autoParams, function(err, data) {
                                    if(err) throw err;
                                });
                            //}
                        }
                    }
                }
            }
            });
        //console.log("Complete");
    };
    databaseOperation(sourcesDates, timeAdded, links, titles, descriptions);
}
//// END

You never called the function DatabaseTime . 您从未调用过函数DatabaseTime Your code just declares the function and does nothing else. 您的代码只声明了该函数,而没有执行其他任何操作。 In order for the function to execute, you must invoke it. 为了执行该功能,必须调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM