Skip to content

Commit

Permalink
Use ini config file instead of env variables to make configuration ea…
Browse files Browse the repository at this point in the history
…sier.
  • Loading branch information
farhadhf committed Feb 25, 2015
1 parent cc3616d commit 7c332d1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
config.ini

26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ git clone https://github.com/Taskulu/tweelead.git
**5)** Copy <a href="https://docs.google.com/spreadsheets/d/1bZRFP5R6DvGTPkDrVhqyQCv8yUMsgLzFHud7kc8J1Zo/edit?usp=sharing">this</a> 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
Expand Down
11 changes: 11 additions & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
@@ -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
40 changes: 16 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -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);
}
});
Expand All @@ -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, {
Expand All @@ -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);
});
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7c332d1

Please sign in to comment.