-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
49 lines (38 loc) · 1.25 KB
/
app.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
const Twitter = require('twitter');
const config = require('./config.js');
const cron = require('node-cron');
const axios = require('axios');
const express = require('express');
const knex = require('knex');
const captureWebsite = require('capture-website');
var makeGithubRequest = require('./controllers/github_controller');
var selectIssues = require('./controllers/issue_select_controller');
var tweetIssues = require('./controllers/twitter_controller');
const app = express();
const db = knex({
client: 'pg',
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true
}
});
const client = new Twitter(config);
cron.schedule('*/5 * * * *', () => {
console.log('started task');
performOperation();
});
async function performOperation() {
var issuesList = await makeGithubRequest(axios, db);
console.log(`Total Issues being considered ${issuesList.length}`);
if (issuesList.length > 0) {
var selectedIssues = await selectIssues(issuesList, db);
console.log(`Selected ${selectedIssues.length} issues.`);
await tweetIssues(selectedIssues, client, captureWebsite, axios);
}
}
app.get('/', (req, res) => {
res.json('it is working!');
});
app.listen(process.env.PORT || 3000, () => {
console.log(`Up and running on port ${process.env.PORT}`);
});