GithubHelp home page GithubHelp logo

Comments (17)

spences10 avatar spences10 commented on May 13, 2024 2

@robbawebba this was quite puzzling for me so I used my own twitter accounts for testing which worked gloriously well.

@amandeepmittal I think this is the way forward, just have contributors use the code base but use their own keys on either a throw away account or one they will be using for their own development.

Also 🎉 🎆 🍾

quite happy with myself at figuring that one out 😎

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024 1

If no one else is looking at this I'm thinking about using level db add a user ID, something like.

db.put('twitterId_encourage', 'true')
db.put('twitterId_congratulate', 'true')

Then destroy the db every 24 hrs so no one is given too many inspirational quotes 😄

https://github.com/Level/level

from 100daysofcode-twitter-bot.

amandeepmittal avatar amandeepmittal commented on May 13, 2024 1

@spences10 why don't you create a prototype of suggested with leveldb, and then we both can test it?

from 100daysofcode-twitter-bot.

amandeepmittal avatar amandeepmittal commented on May 13, 2024 1

@spences10 Is it good to go? No breaks, I guess?

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024 1

Ok, for some reason I couldn't trigger sentiment on my test bot on the #100DaysOfCode tag but the production bot found them just fine

image

I switched to my @DroidScott twitter account for the testing and got the result I wanted on #someTestHashTag and got the result I was after

image

So this is g2g, no changes needed to the PR #30

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024 1

Ok, so I set up this bot on a different account and different hashtag and repeated the test so there are three accounts I'm testing with, so first I test with my personal Twitter account @spences10 output here:

image

I get the output we get on the @_100DaysOfCode bot production console, same but there is only one response from the bot account @DroidScott, so I test with my @ScottDevTweets account

I check the twitter account output:

image

So there is one tweet per user that has tweeted negative sentiment more than once:

image

So, it looks like there must be another instance of the @_100DaysOfCode twitter bot running

Solution?

Regenerate the Twitter keys, @amandeepmittal can you do this?

from 100daysofcode-twitter-bot.

amandeepmittal avatar amandeepmittal commented on May 13, 2024 1

@spences10 Done

from 100daysofcode-twitter-bot.

robbawebba avatar robbawebba commented on May 13, 2024 1

Lol I wish there was an easier way to test twitter bots locally instead of having to use the same auth tokens as production. 😅 This problem is also noted in #22

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

I have been getting multiple encouraging tweets, can we get the id of the tweet that triggered the response and then reply to that so there's an audit trail?

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

Hi @amandeepmittal I have and am currently educating myself with LevelDB, something I thought was quite straight forward has consumed quite a bit of time now.

I have db.js for the database

var level = require('level');  
var path = require('path');

var dbPath = process.env.DB_PATH || path.join(__dirname, 'mydb');  
var db = level(dbPath);

module.exports = db;

And I want to be able to query the db, so in app.js

var db = require('./db', {
  valueEncoding: 'json'
})

db.put('name', 'ID001')
db.put('name', 'ID002')
db.put('name', 'ID003')
db.put('name', 'ID004')
db.put('name', 'ID005')
db.put('name', 'ID006')
db.put('name', 'ID007')

db.createReadStream()
  .on('data', function (entry) {
    console.log(entry.value);
  })

Output is

spences10:~/workspace/level-db $ node app.js
ID006
spences10:~/workspace/level-db $ node app.js
ID007
spences10:~/workspace/level-db $ node app.js
ID007
spences10:~/workspace/level-db $ node app.js
ID005
spences10:~/workspace/level-db $ node app.js
ID007
spences10:~/workspace/level-db $ node app.js
ID007
spences10:~/workspace/level-db $ node app.js
ID006
spences10:~/workspace/level-db $ node app.js
ID005
spences10:~/workspace/level-db $ node app.js
ID003
spences10:~/workspace/level-db $ node app.js
ID007

That's from mashing the node app.js in the terminal

So, I'm trying to work out how to iterate or just get data from the db

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

Added PR #30 for this 👍 @amandeepmittal you can test from my branch if you like

https://github.com/spences10/100DaysOfCode-twitter-bot/tree/add-user-blacklist

or if you prefer I can give you access to my c9 environment as a collaborator, mail me: [email protected]

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

@amandeepmittal yis g2g 😎

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

@amandeepmittal maybe I should explain the changes before you merge?

Added logic to the sentiment detection, and add user name as the key and encourage as the value

There's a check to see if the screen_name is already in the db before the .put

      // if sentiment is Negative and the confidence is above 75%
      if (sentim == 'Negative' && confidence >= 75) {
        // get a random quote
        var phrase = sentiment.randomQuote()
        var screen_name = tweet.user.screen_name
        // Check key isn't in db already, key being the screen_name
        db.get(screen_name, function(err, value) {
          if (typeof(value) !== 'undefined') {
            console.log('ALREADY IN DB USER ', screen_name);
          }
          else {
            // Put a user name and that they have been encouraged 
            db.put(screen_name, 'encourage', function(err) {
              if (err) return console.log('Ooops!', err) // some kind of I/O error
              console.log('LOGGED USER ', screen_name)
              // tweet a random encouragement phrase
              tweetNow('@' + screen_name + ' ' + phrase)
            })
          }
        })
      }

I also added in fs-extra so that the database could be rebuilt each day

var refreshDB = function() {
  var fs = require('fs-extra')

  fs.remove('./blacklistUsersDb', function(err) {
    if (err) return console.error(err)

    console.log('success!')
  })
}

refreshDB()
  // retweet every 24 hrs
setInterval(refreshDB, 60000 * 1440)

Maybe I could add something a bit more detailed other than success for the deletion of the database though.

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

Ok, this is still an issue @Ilyes-Hammadi are you able to add anything to this?

The logging for the database functions as expected, see the output here:

image

That has my twitter handle ScottDevTweets added to the database, but the output from the bot is double as per the original issue:

image

So the next time I tweet with negative sentiment I get this output:

image

So the maximum any user is going to get currently is two every 24 hours, this should be one.

Technically it shouldn't post the two tweets as the second tweet should be handled

        // Check key isn't in db already, key being the screen_name
        db.get(screen_name, function(err, value) {

          if (typeof(value) !== 'undefined') {
            console.log('ALREADY IN DB USER ', screen_name);
          }
          else {
            // Put a user name and that they have been encouraged 
            db.put(screen_name, 'encourage', function(err) {
              if (err) return console.log('Ooops!', err) // some kind of I/O error

              console.log('LOGGED USER ', screen_name)

              // tweet a random encouragement phrase
              tweetNow('@' + screen_name + ' ' + phrase)

            })
          }

        })

If the user key is in the database then tweetNow isn't called, @amandeepmittal is that your understanding too?

I'm going to do some more testing on the #someTestHashTag I'd like to hear peoples thoughts 😄 ❓

from 100daysofcode-twitter-bot.

spences10 avatar spences10 commented on May 13, 2024

Anyone going to own up to leaving the bot running?

from 100daysofcode-twitter-bot.

amandeepmittal avatar amandeepmittal commented on May 13, 2024

@robbawebba The purpose of giving access to tokens is that user can test themselves. But I guess, the purpose is no longer fulfilled.

from 100daysofcode-twitter-bot.

amandeepmittal avatar amandeepmittal commented on May 13, 2024

@spences10 you were absolutely right. Someone was running another instance of the bot. This issue can be closed once again!

from 100daysofcode-twitter-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.