diff --git a/.gitignore b/.gitignore index 07e6e47..a7a21e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /node_modules +config.ini + diff --git a/README.md b/README.md index c90c698..bdf5693 100644 --- a/README.md +++ b/README.md @@ -32,19 +32,19 @@ git clone https://github.com/Taskulu/tweelead.git **5)** Copy this spreadsheet to your Google Drive. We'll need the spreadsheet key from the URL later. > URL format: https://docs.google.com/spreadsheets/d/{SPREADSHEET-KEY}/edit -**6)** Add the constants to your enviroment from code you downloaded in step **1**: -```bash -export GOOGLE_EMAIL='youremail@gmail.com' -// If you use Google 2 Factor Authentication this will be the app key you generated in step 4 -export GOOGLE_PASSWORD='YOUR-PASSWORD123!#' -export GOOGLE_SPREADSHEET="SPREADSHEET-KEY"; -export AYLIEN_APP_ID='YOUR-AYLIEN-APPLICATION-ID' -export AYLIEN_APP_KEY='YOUR-AYLIEN-APPLICATION-KEY' -export TW_CONSUMER_KEY='TWITTER-CONSUMER-KEY' -export TW_CONSUMER_SEC='TWITTER-CONSUMER-SECRET' -export TW_ACCESS_TOKEN_KEY='TWITTER-ACCESS-TOKEN-KEY' -export TW_ACCESS_TOKEN_SEC='TWITTER-ACCESS-TOKEN-SECRET' -export CSV_KEYWORDS='comma,separated,list,of,keywords,you,want,to,monitor' +**6)** Rename config.ini.example to config.ini and set the values: +```ini +GOOGLE_EMAIL = youremail@gmail.com +GOOGLE_PASSWORD = YOUR-PASSWORD123!# +GOOGLE_SPREADSHEET = GOOGLE-SPREADSHEET-KEY +AYLIEN_APP_ID = YOUR-AYLIEN-APPLICATION-ID +AYLIEN_APP_KEY = YOUR-AYLIEN-APPLICATION-KEY +TW_CONSUMER_KEY = TWITTER-CONSUMER-KEY +TW_CONSUMER_SEC = TWITTER-CONSUMER-SECRET +TW_ACCESS_TOKEN_KEY = TWITTER-ACCESS-TOKEN-KEY +TW_ACCESS_TOKEN_SEC = TWITTER-ACCESS-TOKEN-SECRET +CSV_KEYWORDS = comma,separated,list,of,your,keywords +LANGUAGE = en ``` **7)** What kind of tweets are you looking for? Configure the POLARITY_OPTIONS in index.js diff --git a/config.ini.example b/config.ini.example new file mode 100644 index 0000000..1197389 --- /dev/null +++ b/config.ini.example @@ -0,0 +1,11 @@ +GOOGLE_EMAIL = youremail@gmail.com +GOOGLE_PASSWORD = YOUR-PASSWORD123!# +GOOGLE_SPREADSHEET = GOOGLE-SPREADSHEET-KEY +AYLIEN_APP_ID = YOUR-AYLIEN-APPLICATION-ID +AYLIEN_APP_KEY = YOUR-AYLIEN-APPLICATION-KEY +TW_CONSUMER_KEY = TWITTER-CONSUMER-KEY +TW_CONSUMER_SEC = TWITTER-CONSUMER-SECRET +TW_ACCESS_TOKEN_KEY = TWITTER-ACCESS-TOKEN-KEY +TW_ACCESS_TOKEN_SEC = TWITTER-ACCESS-TOKEN-SECRET +CSV_KEYWORDS = comma,separated,list,of,your,keywords +LANGUAGE = en diff --git a/index.js b/index.js index 1e7dde2..b853b9c 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,10 @@ -var Twitter = require('twitter'); -var AYLIENTextAPI = require("aylien_textapi"); -var GoogleSpreadsheet = require("google-spreadsheet"); +var Twitter = require('twitter'), + AYLIENTextAPI = require("aylien_textapi"), + GoogleSpreadsheet = require("google-spreadsheet"), + fs = require('fs'), + ini = require('ini'); -const GOOGLE_EMAIL = process.env.GOOGLE_EMAIL; -const GOOGLE_PASSWORD = process.env.GOOGLE_PASSWORD; -const GOOGLE_SPREADSHEET = process.env.GOOGLE_SPREADSHEET; -const AYLIEN_APP_ID = process.env.AYLIEN_APP_ID; -const AYLIEN_APP_KEY = process.env.AYLIEN_APP_KEY; -const TW_CONSUMER_KEY = process.env.TW_CONSUMER_KEY; -const TW_CONSUMER_SEC = process.env.TW_CONSUMER_SEC; -const TW_ACCESS_TOKEN_KEY = process.env.TW_ACCESS_TOKEN_KEY; -const TW_ACCESS_TOKEN_SEC = process.env.TW_ACCESS_TOKEN_SEC; -const CSV_KEYWORDS = process.env.CSV_KEYWORDS; -const LANGUAGE = process.env.LANGUAGE; +var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8')) // Confidence level is always between 0.5 and 1, therefore in the example below // setting the positive confidence level to 0.49 instead of 0 does not make any @@ -27,18 +19,18 @@ const POLARITY_OPTIONS = { }; -var gsheet = new GoogleSpreadsheet(process.env.GOOGLE_SPREADSHEET); +var gsheet = new GoogleSpreadsheet(config.GOOGLE_SPREADSHEET); var textapi = new AYLIENTextAPI({ - application_id: AYLIEN_APP_ID, - application_key: AYLIEN_APP_KEY + application_id: config.AYLIEN_APP_ID, + application_key: config.AYLIEN_APP_KEY }); var client = new Twitter({ - consumer_key: TW_CONSUMER_KEY, - consumer_secret: TW_CONSUMER_SEC, - access_token_key: TW_ACCESS_TOKEN_KEY, - access_token_secret: TW_ACCESS_TOKEN_SEC + consumer_key: config.TW_CONSUMER_KEY, + consumer_secret: config.TW_CONSUMER_SEC, + access_token_key: config.TW_ACCESS_TOKEN_KEY, + access_token_secret: config.TW_ACCESS_TOKEN_SEC }); function checkLanguage(tweet) { @@ -48,7 +40,7 @@ function checkLanguage(tweet) { textapi.language({"text": tweet.text}, function(error, languageResponse) { if (handleError(error)) return; - if (languageResponse.lang == LANGUAGE) { + if (languageResponse.lang == config.LANGUAGE) { measureSentiment(tweet); } }); @@ -70,7 +62,7 @@ function measureSentiment(tweet) { } function logTweetToGoogle(tweet, response) { - gsheet.setAuth(GOOGLE_EMAIL, GOOGLE_PASSWORD, function(err){ + gsheet.setAuth(config.GOOGLE_EMAIL, config.GOOGLE_PASSWORD, function(err){ if (handleError) return; gsheet.addRow(1, { @@ -89,7 +81,7 @@ function handleError(err) { return false; } -client.stream('statuses/filter', {track: CSV_KEYWORDS}, function(stream) { +client.stream('statuses/filter', {track: config.CSV_KEYWORDS}, function(stream) { stream.on('data', checkLanguage); stream.on('error', handleError); }); diff --git a/package.json b/package.json index f52c63c..248553b 100644 --- a/package.json +++ b/package.json @@ -13,16 +13,19 @@ "social" ], "author": "Taskulu", - "contributors": ["Farhad Hedayati"], + "contributors": [ + "Farhad Hedayati" + ], "license": "MIT", "bugs": { "url": "https://github.com/taskulu/tweelead/issues" }, "homepage": "https://github.com/taskulu/tweelead", "dependencies": { - "twitter": "latest", - "aylien_textapi": "latest", - "google-spreadsheet": "latest" + "aylien_textapi": "latest", + "google-spreadsheet": "latest", + "ini": "latest", + "twitter": "latest" }, "engines": { "node": "0.10.x"