-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (22 loc) · 774 Bytes
/
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
const cron = require('node-cron');
const {KEY, URL, DB_URL, DB_NAME, LOCATIONS, CRON} = require('./config');
const fetch = require('./fetch');
const { initDB, write } = require('./database');
// request data and store it in mongo
const grab = async () => {
await initDB(DB_URL, DB_NAME);
await cron.schedule(CRON, async () => {
try {
// Fetch data for each location
await LOCATIONS.forEach(async loc => {
const data = await fetch(URL, KEY, loc);
console.log(`[API] New Incoming for ${loc}`)
// console.log(res);
await write(data);
})
} catch (err) {
console.error(err);
}
})
}
grab();