-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (51 loc) · 1.59 KB
/
server.js
File metadata and controls
61 lines (51 loc) · 1.59 KB
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
const express = require('express')
, server = express()
, Twit = require('twit')
, BodyParser = require('body-parser')
, Geocode = require('./lib/Geocode')
, Dummy = require('./lib/Dummy')
, Processor = require('./lib/Processor')
, Client = require('./lib/Client')
, WebHook = require('./lib/WebHook')
, config = require('./config/config.json')
, port = 9006
, T = new Twit({
consumer_key: config.consumer_key
, consumer_secret: config.consumer_secret
, access_token: config.access_token
, access_token_secret: config.access_token_secret
, timeout_ms: 60 * 1000
})
, client = new Client(T)
, myName = 'TransportMeTo'
, webhook = new WebHook()
const start = () => {
// Dummy.startDummy(T)
var stream = T.stream('user', { user: myName})
stream.on('tweet', function (tweet) {
console.log("received tweet");
var nameId = tweet.id_str;
var username = tweet.user.screen_name;
var json = JSON.stringify(tweet)
if(username.indexOf(myName) !== -1) {
return
}
client.processTweet(tweet)
})
stream.on('error', err => {
console.log(err)
})
}
(async () => {
let ready = await client.getReady()
start()
})()
server.use(BodyParser.urlencoded({ extended: false }))
server.use(BodyParser.json())
server.get('/', (req, res) => {
res.status(200).send("Go Home!")
})
server.post('/webhook/apiairequest', webhook.reverseGeocode.bind(webhook) )
server.listen(port, listen => {
console.log("server listening on ", port);
})