-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
98 lines (74 loc) · 4.12 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
"use strict";
/**
* Created by dowling on 27/08/16.
*/
var hashpokemongo = require("./hashpokemongo");
var Twitter = require("twitter");
var options = {
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token_key: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
};
var client = new Twitter(options);
var db = "mongodb://localhost:27017/test";
hashpokemongo.TwitterSentimentsMiner.start(client, db, 5 * 1000, true); // Mine every 5 seconds
var pokemonSearchTerms = 'caught #pokemongo,saw #pokemongo,found #pokemongo,appeared #pokemongo,attacked #pokemongo,pokemon catch,pokemon saw,pokemon attack,pokemon find,pokemon caught,pokemon attacked,pokemon found,pokemon appeared,#foundPokemon,#caughtPokemon,#pokemongo,a wild appeared until #pokemongo';
var pokemonNames = "bulbasaur, ivysaur, venusaur, charmander, charmeleon, charizard, squirtle, wartortle, blastoise, caterpie, metapod, butterfree, weedle, kakuna, beedrill, pidgey, pidgeotto, pidgeot, rattata, raticate, spearow, fearow, ekans, arbok, pikachu, raichu, sandshrew, sandslash, nidoran ♀, nidorina, nidoqueen, nidoran ♂, nidorino, nidoking, clefairy, clefable, vulpix, ninetales, jigglypuff, wigglytuff, zubat, golbat, oddish, gloom, vileplume, paras, parasect, venonat, venomoth, diglett, dugtrio, meowth, persian, psyduck, golduck, mankey, primeape, growlithe, arcanine, poliwag, poliwhirl, poliwrath, abra, kadabra, alakazam, machop, machoke, machamp, bellsprout, weepinbell, victreebel, tentacool, tentacruel, geodude, graveler, golem, ponyta, rapidash, slowpoke, slowbro, magnemite, magneton, farfetch'd, doduo, dodrio, seel, dewgong, grimer, muk, shellder, cloyster, gastly, haunter, gengar, onix, drowzee, hypno, krabby, kingler, voltorb, electrode, exeggcute, exeggutor, cubone, marowak, hitmonlee, hitmonchan, lickitung, koffing, weezing, rhyhorn, rhydon, chansey, tangela, kangaskhan, horsea, seadra, goldeen, seaking, staryu, starmie, mr. mime, scyther, jynx, electabuzz, magmar, pinsir, tauros, magikarp, gyarados, lapras, ditto, eevee, vaporeon, jolteon, flareon, porygon, omanyte, omastar, kabuto, kabutops, aerodactyl, snorlax, articuno, zapdos, moltres, dratini, dragonair, dragonite, mewtwo, mew";
var stream = client.stream('statuses/filter', {track: pokemonSearchTerms + "," + pokemonNames});
stream.on("data", function (data) {
if (data.user) {
//console.log("Got tweet by '" + data.user.screen_name + "': " + data.text);
}
});
var io = require('socket.io')(3000);
var mobOptions = {
io: io,
mobSizeThreshold: 5,
maxClusterAge: 5 * 60,
maxDistanceThreshold: 300
};
hashpokemongo.SentimentFeed({io: io}).startSentimentFeed(stream);
hashpokemongo.MobDetection({io: io}).startPokeMobDetection(stream, function(error) {
console.log(error);
});
//Lets require/import the HTTP module
var express = require('express');
var app = express();
app.use(express.static('demo'));
app.get('/sentiments/:pokemonNumber', function (req, res) {
console.log("Get pokemon sentiments");
try {
hashpokemongo.TwitterSentiments.setimentsForPokemon(db, req.params.pokemonNumber, function (data) {
console.log("Query Repssone: ", data);
res.json(data);
},
function (error) {
console.log(error);
res.status(500);
res.send(error);
});
} catch (e) {
res.status(500);
res.send(e);
}
});
app.get('/sentiments/:pokemonNumber/:lat/:lng', function (req, res) {
try {
hashpokemongo.TwitterSentiments.sentimentsForPokemonByLocation(db, req.params.pokemonNumber, parseFloat(req.params.lat), parseFloat(req.params.lng), function (data) {
console.log("Query Repsone: ", data);
res.json(data);
},
function (error) {
console.log(error);
res.status(500);
res.send(error);
});
} catch (e) {
res.status(500);
res.send(e);
}
});
app.listen(8080, function () {
console.log('Example app listening on port 3000!');
});