node-csfd-api
Version:
ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)
1 lines • 2.26 kB
Source Map (JSON)
{"version":3,"file":"cinema.service.cjs","names":["fetchPage","cinemasUrl","parseCinema","getCinemaId","getCinemaUrl","getCinemaCoords","getGroupedFilmsByDate"],"sources":["../../src/services/cinema.service.ts"],"sourcesContent":["import { HTMLElement, parse } from 'node-html-parser';\nimport { CSFDCinema, CSFDCinemaPeriod } from '../dto/cinema';\nimport { fetchPage } from '../fetchers';\nimport { CSFDOptions } from '../types';\nimport { cinemasUrl } from '../vars';\nimport {\n getCinemaCoords,\n getCinemaId,\n getCinemaUrl,\n getGroupedFilmsByDate,\n parseCinema\n} from './../helpers/cinema.helper';\n\nexport class CinemaScraper {\n public async cinemas(\n district: number = 1,\n period: CSFDCinemaPeriod = 'today',\n options?: CSFDOptions\n ): Promise<CSFDCinema[]> {\n const url = cinemasUrl(district, period, { language: options?.language });\n const response = await fetchPage(url, { ...options?.request });\n const cinemasHtml = parse(response);\n\n const contentNode = cinemasHtml.querySelectorAll('#snippet--cinemas section[id*=\"cinema-\"]');\n\n return this.buildCinemas(contentNode);\n }\n\n private buildCinemas(contentNode: HTMLElement[]): CSFDCinema[] {\n const cinemas: CSFDCinema[] = [];\n\n contentNode.forEach((x) => {\n const cinemaInfo = parseCinema(x);\n const cinema: CSFDCinema = {\n id: getCinemaId(x),\n name: cinemaInfo?.name,\n city: cinemaInfo?.city,\n url: getCinemaUrl(x),\n coords: getCinemaCoords(x),\n screenings: getGroupedFilmsByDate(x)\n };\n cinemas.push(cinema);\n });\n\n return cinemas;\n }\n}\n"],"mappings":";;;;;AAaA,IAAa,gBAAb,MAA2B;CACzB,MAAa,QACX,WAAmB,GACnB,SAA2B,SAC3B,SACuB;EAKvB,MAAM,eAAA,GAAA,iBAAA,MAAA,CAFoB,MADHA,cAAAA,UADXC,aAAAA,WAAW,UAAU,QAAQ,EAAE,UAAU,SAAS,SAAS,CACpC,GAAG,EAAE,GAAG,SAAS,QAAQ,CAAC,CAG/B,CAAC,CAAC,iBAAiB,4CAA0C;EAE3F,OAAO,KAAK,aAAa,WAAW;CACtC;CAEA,aAAqB,aAA0C;EAC7D,MAAM,UAAwB,CAAC;EAE/B,YAAY,SAAS,MAAM;GACzB,MAAM,aAAaC,sBAAAA,YAAY,CAAC;GAChC,MAAM,SAAqB;IACzB,IAAIC,sBAAAA,YAAY,CAAC;IACjB,MAAM,YAAY;IAClB,MAAM,YAAY;IAClB,KAAKC,sBAAAA,aAAa,CAAC;IACnB,QAAQC,sBAAAA,gBAAgB,CAAC;IACzB,YAAYC,sBAAAA,sBAAsB,CAAC;GACrC;GACA,QAAQ,KAAK,MAAM;EACrB,CAAC;EAED,OAAO;CACT;AACF"}