-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (26 loc) · 1.02 KB
/
index.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
import express from 'express';
import * as path from 'path';
import * as url from 'url';
import * as dotenv from 'dotenv';
import * as cron from 'node-cron';
import { engine } from 'express-handlebars';
import { scrapTask, prevScrapping } from './scrapper.js';
dotenv.config();
const app = express();
app.engine('handlebars', engine({defaultLayout: 'scrapping'}));
app.set('view engine', 'handlebars');
app.set('views', './views');
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', (req, res, next) => {
res.render('scrapping', {items: prevScrapping});
})
const scrapPath = 'https://www.kavak.com/ar/autos-Argo/ciudad-Buenos_Aires/autos-usados';
cron.schedule('0 0 */12 * *', () => {
scrapTask(scrapPath);
})
// Cheat to keep Heroku app alive ;)
setInterval(() => {
http.get("https://kavak-scrapper.herokuapp.com/");
}, 25 * 60 * 1000); // every 25 minutes
app.listen(process.env.PORT || 8000, () => console.log('App running'));