mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-24 22:22:50 -05:00
Move data fetching into lib
This commit is contained in:
@@ -3,5 +3,3 @@ export const HEIGHT = 1080
|
||||
export const GRID_COUNT = 3
|
||||
export const SPACE_WIDTH = Math.floor(WIDTH / GRID_COUNT)
|
||||
export const SPACE_HEIGHT = Math.floor(HEIGHT / GRID_COUNT)
|
||||
export const DATA_URL = 'https://woke.net/csv'
|
||||
export const REFRESH_INTERVAL = 5 * 60 * 1000
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import { app, BrowserWindow, BrowserView, ipcMain, shell } from 'electron'
|
||||
import { interpret } from 'xstate'
|
||||
import fetch from 'node-fetch'
|
||||
import csv from 'csvtojson'
|
||||
|
||||
import { pollPublicData } from './data'
|
||||
import viewStateMachine from './viewStateMachine'
|
||||
import { boxesFromSpaceURLMap } from './geometry'
|
||||
|
||||
@@ -12,19 +11,9 @@ import {
|
||||
GRID_COUNT,
|
||||
SPACE_WIDTH,
|
||||
SPACE_HEIGHT,
|
||||
DATA_URL,
|
||||
REFRESH_INTERVAL,
|
||||
} from '../constants'
|
||||
|
||||
async function fetchData() {
|
||||
// TODO: stable idxs
|
||||
const resp = await fetch(DATA_URL)
|
||||
const text = await resp.text()
|
||||
const data = await csv().fromString(text)
|
||||
return data.filter((d) => d.Link && d.Status === 'Live')
|
||||
}
|
||||
|
||||
function main() {
|
||||
async function main() {
|
||||
const mainWin = new BrowserWindow({
|
||||
x: 0,
|
||||
y: 0,
|
||||
@@ -162,13 +151,10 @@ function main() {
|
||||
overlayView.webContents.openDevTools()
|
||||
})
|
||||
|
||||
async function refreshData() {
|
||||
const data = await fetchData()
|
||||
for await (const data of pollPublicData()) {
|
||||
mainWin.webContents.send('stream-data', data)
|
||||
overlayView.webContents.send('stream-data', data)
|
||||
}
|
||||
setInterval(refreshData, REFRESH_INTERVAL)
|
||||
refreshData()
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
|
||||
Reference in New Issue
Block a user