Comments (17)
@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.
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.
@spences10 why don't you create a prototype of suggested with leveldb, and then we both can test it?
from 100daysofcode-twitter-bot.
@spences10 Is it good to go? No breaks, I guess?
from 100daysofcode-twitter-bot.
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
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
So this is g2g, no changes needed to the PR #30
from 100daysofcode-twitter-bot.
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:
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:
So there is one tweet per user that has tweeted negative sentiment more than once:
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.
@spences10 Done
from 100daysofcode-twitter-bot.
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.
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.
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.
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.
@amandeepmittal yis g2g 😎
from 100daysofcode-twitter-bot.
@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.
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:
That has my twitter handle ScottDevTweets added to the database, but the output from the bot is double as per the original issue:
So the next time I tweet with negative sentiment I get this output:
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.
Anyone going to own up to leaving the bot running?
from 100daysofcode-twitter-bot.
@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.
@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)
- Add tests for env variables
- Use `in_reply_to_status_id:`
- Consider abstracting out `quotes.json` HOT 3
- Moar badges HOT 6
- Contributing needs work HOT 4
- Amend slack channel url HOT 1
- Change Slack Link in the Tweet HOT 1
- Add Emojis in Tweet responders? HOT 5
- Consider adding development branch HOT 12
- Consider adding .github community folder
- [RFC] Set up Travis CI workflow HOT 3
- Getting this to run issue and deploying with zeit question/issue HOT 3
- Update docs to the KCD README pattern HOT 9
- Blacklist these Users from Twitter HOT 8
- The 2nd ul in the contributing sections setup section of the readme goes to a 404 page HOT 1
- Practice bot HOT 3
- Remove yarn.lock file
- Welcome bot! Respond to the user when committing to 100DaysOfCode HOT 4
- Promote the Slack Channel HOT 3
- Sentiment API down or out of service
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 100daysofcode-twitter-bot.