Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

javascript - How to fix brain.js error while using twitter api

Hi im trying to make a neural network that replies to tweets with premade phrases i keep getting the error

C:UsersoichOneDriveDocumentsruhruh>node script1.js
node:internal/modules/cjs/loader:928
  throw err;
  ^

Error: Cannot find module 'C:UsersoichOneDriveDocumentsruhruhscript1.js'
[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:769:27)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)[39m
[90m    at node:internal/main/run_main_module:17:47[39m {
  code: [32m'MODULE_NOT_FOUND'[39m,
  requireStack: []
}

I want to know how I could fix this and why its happening, PS. I am new to node.js

var TwitterPackage = require('twitter'); const fs = require('fs');

var secret = {
    consumer_key: '',
    consumer_secret: '',
    access_token_key: '', // These are filled out 
    access_token_secret: ''
}
var Twitter = new TwitterPackage(secret);

// Call the stream function and pass in 'statuses/filter', our filter object, and our callback
Twitter.stream('statuses/filter', { track: '#obama' }, function (stream) {

    // ... when we get tweet data...
    stream.on('data', function (tweet) {

        // print out the text of the tweet that came in
        console.log(tweet.text);

        const brain = require('brain.js')
        const data = require('./tweet.json')



        const net = new brain.recurrent.LSTM(); {
            (
                hiddenlayers = [3, 3]

            )
        }

        const trainingData = data.map(item => ({
            input: item.income,
            output: item.outcome


        }));

        const trainRes = net.train(trainingData, {
            iterations: 5,
            callback: step => console.log(step)
        });



        const output = net.run(tweet.text)

        console.log(`Favorites: ${output}`);


        //build our reply object
        var statusObj = { status: "Hi @" + tweet.user.screen_name + `${output}` }

        //call the post function to tweet something
        Twitter.post('statuses/update', statusObj, function (error, tweetReply, response) {

            //if we get an error print it out
            if (error) {
                console.log(error);
            }

            //print the text of the tweet we sent out
            console.log(tweetReply.text);
        });
    });

    // ... when we get an error...
    stream.on('error', function (error) {
        //print out the error
        console.log(error);
    });
});

im using Brain.js And Twitter. To install twitter I did npm i twitter if thats the right package and yes i know the AUTH details are not filled out i know those need to be filled out but when i do fill them out it still doesnt work

question from:https://stackoverflow.com/questions/65875818/how-to-fix-brain-js-error-while-using-twitter-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

nevermind for some reason the name of the file was causing it not exist


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...