Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
feat(add retweet): retweet function [currently broken] using searchId
Browse files Browse the repository at this point in the history
retweet function added uses searchId, searchId returning expected result but not retweeting yes
  • Loading branch information
spences10 committed Apr 15, 2017
1 parent c10d473 commit 7ef2e5d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getFunName
} from './helpers/helpers'
import searchResult from './helpers/search'
import retweet from './helpers/retweet'

const client = new Twiter(config.twitter)

Expand All @@ -23,8 +24,11 @@ const tweetNow = async (txt) => {
}
}

tweetNow(getFunName())
setInterval(() => tweetNow(getFunName()), 1000 * 60 * 90)
// tweetNow(getFunName())
// setInterval(() => tweetNow(getFunName()), 1000 * 60 * 90)

searchResult()
setInterval(() => searchResult(), 1000 * 5)
// searchResult()
// setInterval(() => searchResult(), 1000 * 5)

retweet()
setInterval(() => retweet(), 1000 * 5)
12 changes: 12 additions & 0 deletions src/helpers/getSentiment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sentiment from '.'

const httpCall = sentiment.init()

httpCall.send(`txt=${'not good bad bad'}`).end(result => {
const sentim = result.body.result.sentiment;
const confidence = parseFloat(result.body.result.confidence)
console.log(confidence, sentim)
if (sentim === 'Negative' && confidence >= 75) {
console.log('RETWEET NEG NEG NEG', sentim, 'not good bad bad')
}
})
2 changes: 1 addition & 1 deletion src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export function getFunName() {

const nouns = ['women', 'men', 'children', 'teeth', 'feet', 'people', 'leaves', 'mice', 'geese', 'halves', 'knives', 'wives', 'lives', 'elves', 'loaves', 'potatoes', 'tomatoes', 'cacti', 'foci', 'fungi', 'nuclei', 'syllabuses', 'analyses', 'diagnoses', 'oases', 'theses', 'crises', 'phenomena', 'criteria', 'data']

return `${rando(adjectives)} ${rando(adjectives)} ${rando(nouns)} with ${rando(nouns)}`
return `All I have to say is ${rando(adjectives)} ${rando(adjectives)} ${rando(nouns)} with ${rando(nouns)}`
}
21 changes: 21 additions & 0 deletions src/helpers/retweet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Twiter from 'twitter'
import config from '../config'
import searchId from './search'

const client = new Twiter(config.twitter)

const retweet = async () => {
let res
console.log(client)
try {
res = await client.post('statuses/retweet/:id', {
id: searchId()
})
console.log('RES :', res, 'CLIENT :', client)
} catch (err) {
console.log('ERR: ', err)
}
console.log('RES :', res)
}

export default retweet
10 changes: 5 additions & 5 deletions src/helpers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const searchResult = async () => {
let res
try {
res = await client.get('search/tweets', params)
// const randoUser = rando(res.data.statuses).user.scree_name
// console.log('rando user = ', randoUser)
} catch (err) {
console.log('error = ', err)
}

// const randoUser = rando(res.data.statuses).user.scree_name
// console.log('rando user = ', randoUser)
// console.log(JSON.stringify(res))
console.log(rando(res.statuses).user.screen_name)
console.log(rando(res.statuses).text)
// console.log(rando(res.statuses).user.screen_name)
// console.log(rando(res.statuses).text)
console.log(rando(res.statuses).id_str)
return rando(res.statuses).id_str
}

export default searchResult
4 changes: 1 addition & 3 deletions src/helpers/sentiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import unirest from 'unirest'

const sentiment = {}

sentiment.init = function () {
return unirest.post('https://community-sentiment.p.mashape.com/text/')
sentiment.init = () => unirest.post('https://community-sentiment.p.mashape.com/text/')
.header('X-Mashape-Key', process.env.SENTIMENT_KEY)
.header('Content-Type', 'application/x-www-form-urlencoded')
.header('Accept', 'application/json')
}

export default sentiment

0 comments on commit 7ef2e5d

Please sign in to comment.