mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-27 07:22:50 -05:00
Move data fetching into lib
This commit is contained in:
18
src/node/data.js
Normal file
18
src/node/data.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { promisify } from 'util'
|
||||
import fetch from 'node-fetch'
|
||||
import csv from 'csvtojson'
|
||||
|
||||
const sleep = promisify(setTimeout)
|
||||
|
||||
const PUBLIC_DATA_URL = 'https://woke.net/csv'
|
||||
const PUBLIC_DATA_REFRESH_INTERVAL = 5 * 60 * 1000
|
||||
|
||||
export async function* pollPublicData() {
|
||||
while (true) {
|
||||
const resp = await fetch(PUBLIC_DATA_URL)
|
||||
const text = await resp.text()
|
||||
const data = await csv().fromString(text)
|
||||
yield data.filter((d) => d.Link && d.Status === 'Live')
|
||||
sleep(PUBLIC_DATA_REFRESH_INTERVAL)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user