import { get } from "axios"; import Debug from "debug"; import { writeFileSync } from "fs"; import { Cache } from "./cache"; import { ICSGenerator } from "./ics-generator"; import { Calendar, Event, Language, PageData, Sport, Team } from "./types"; const BASE_URL = "https://www.olympics.com"; const BASE_SCHEDULE_PATH = "milano-cortina-2026/schedule/overview"; export class Scraper { private cache = new Cache(); private debug = Debug("olympics-calendar:scraper"); private events: Event[] = []; private languages: Language[] = []; private nocs: Team[] = []; private sports: Sport[] = []; private async getPageData(path: string): Promise { this.debug(`getPageData: path=${path}`); if (!this.cache.has(path)) { const url = `${BASE_URL}${path}`; this.debug(url); const response = await get(url, { headers: { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36" }, }); const page = await response.data; const dataMatch = page.match( /