This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
115 lines (98 loc) · 3.07 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const json2csv = require('json2csv');
const mkdirp = require('mkdirp');
const fs = require('fs');
const twitterQuery = require('./twitterQuery');
const piQuery = require('./piQuery');
const utils = require('./utils')
const dotenv = require('dotenv').config()
// Create variables to hold results
let tweets = [];
utils.readPlayersFromFile(process.env.PLAYERS_ALL, function(err,players){
if(err){
console.log('here')
console.log(err);
}
else{
for(let i = 0; i < players.length; i++) {
console.log('index', i)
console.log('players', players[i])
twitterQuery.getTweets(players[i], getInsight)
}
}
})
function getInsight(twitterErr, twitterData, player){
if(twitterErr){
console.log(twitterErr);
}
else{
if(twitterData){
for(let i=0; i < twitterData.length; i ++){
twitterData[i].text = twitterData[i].text.replace(/https.+/g,'')
let contentObject = {
content: twitterData[i].text,
};
tweets.push(contentObject);
}
}
writeTweetsTofile('./results/tweets-analysed-' + player.Name + '.csv', tweets, ['content'], function(writeErr){
if(writeErr){
console.log(writeErr);
}
});
}
// console.log(tweets)
piQuery.getPersonalityInsight(twitterErr, player.Name, player.Position, tweets, processInsights);
}
function processInsights(err, personalityResult){
console.dir(personalityResult)
writeCsvDataTofile('./results/' + personalityResult.Name +'.csv',personalityResult, ['Name', 'Position',
'emotionalRange','agreeableness','conscientiousness', 'openness', 'extraversion',
// Emotional Range
'anger', 'anxiety', 'depression','immoderation','self_consciousness', 'vulnerability',
// Agreeableness
'altruism', 'cooperation', 'modesty', 'morality', 'sympathy', 'trust',
// Conscientiousness
'achievement_striving','cautiousness','dutifulness', 'orderliness', 'self_discipline', 'self_efficacy',
// Openness
'adventurousness', 'artistic_interests', 'emotionality', 'imagination', 'intellect', 'liberalism',
// Extraversion
'activity_level', 'assertiveness', 'cheerfulness', 'excitement_seeking', 'friendliness', 'gregariousness'
], function(writeErr){
if(writeErr){
console.log(writeErr);
}
});
}
function writeCsvDataTofile(file, data, fields, callback){
let getDirName = require('path').dirname;
mkdirp(getDirName(file), function(err){
if(err){
return callback(err);
}
let csv = json2csv({ data: data, fields: fields });
fs.writeFile(file, csv, function(err) {
if(err){
console.log(err);
}
callback(err);
});
});
}
function writeTweetsTofile(file, data, fields, callback) {
let getDirName = require('path').dirname;
mkdirp(getDirName(file), function(err){
if(err){
return callback(err);
}
let csv = json2csv({ data: data, fields: fields });
fs.writeFile(file, csv, function(err) {
if(err){
console.log(err);
}
callback(err);
});
})
}
module.exports = {
writeCsvDataTofile: writeCsvDataTofile
};