-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
44 lines (41 loc) · 1.39 KB
/
app.ts
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
import fs from 'fs'
import yaml from 'yaml'
import chalk from 'chalk'
import { Config } from './typescript/interfaces'
import cron from 'node-cron'
import { fetchAll } from './scrape/controller'
import initServer from './express-modules/create-server'
import fetchRthkNews from './scrape/rthk-news'
let config: Config
fs.promises
.readFile('./config.yaml', 'utf-8')
.then(async (data) => {
config = yaml.parse(data)
// Create folder if hashes not found
if (!fs.existsSync('./public/hash.json')) {
fs.mkdirSync('public')
fs.mkdirSync('public/chunked')
if (!fs.existsSync('./public/fullJSON')) {
fs.mkdirSync('public/fullJSON')
}
console.info(
chalk.yellow(
`[app] Hashes not found, rebuilding chunks and hashses`
)
)
await fetchAll(config)
}
initServer(config)
cron.schedule(config.scraper.cron, async () => {
console.log(chalk.grey('[app] Cron job task run'))
await fetchAll(config)
})
cron.schedule(config.scraper.newsCron, async () => {
await fetchRthkNews()
})
})
.catch((err) => {
console.error(chalk.red(`[app] Error while loading config: ${err}`))
console.error(chalk.red(`[app] Exiting due to error`))
return
})