import 'dotenv/config' import puppeteer from 'puppeteer' import fetchILMeteo from './scrapers/iLMeteo.js' import fetch3Bmeteo from './scrapers/3Bmeteo.js' import fetchAeronauticaMilitare from './scrapers/AeronauticaMilitare.js' import fetchOpenMeteo from './scrapers/OpenMeteo.js' export default class WeatherScraper { constructor() { this.lock = false this.data = {} } async init(opts) { const NIX_OPS = { executablePath: process.env.NIX_CHROMIUM_PATH, } const OPTS = process.env.ON_NIX ? NIX_OPS : {} this.browser = await puppeteer.launch(OPTS) await this.fetch() } async fetch() { const timestamp = new Date().getTime() if (this.lock) { console.log(`[${timestamp}] skipped (locked)`) return } this.lock = true console.log(`[${timestamp}] updating`) const [ // Comment out unwanted fields iLMeteo, treBmeteo, openMeteo, aeronauticaMilitare, ] = await Promise.all([ fetchILMeteo(this.browser), fetch3Bmeteo(this.browser), fetchOpenMeteo(), fetchAeronauticaMilitare(this.browser), ]) console.log(`[${timestamp}] updated`) this.data = { timestamp, iLMeteo, treBmeteo, openMeteo, aeronauticaMilitare, } this.lock = false } }