UNPKG

egypt-banks-scraper

Version:
57 lines (48 loc) 1.24 kB
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["scraper"] }] */ import cheerio from 'cheerio'; import Bank from './Bank'; import { banksNames } from './banks_names'; export default class ABK extends Bank { constructor() { const url = 'http://www.abkegypt.com/rates_abk.aspx'; const selector = '.BLUE_TEXT, .ORANGE_TEXT'; super(banksNames.ABK, url, selector); } /** * Scrape rates from html * @param {Object} html html of bank web page to scrape */ scraper(html) { const $ = cheerio.load(html); const tableRows = $('.BLUE_TEXT, .ORANGE_TEXT'); const rates = []; tableRows.each((index, row) => { const currencyCode = $(row) .children() .eq(0) .text() .trim(); let buyRate = $(row) .children() .eq(3) .text() .trim(); let sellRate = $(row) .children() .eq(4) .text() .trim(); // Fix JPY rate to be for 100 notes if (currencyCode === 'JPY') { buyRate *= 100; sellRate *= 100; } rates.push({ code: currencyCode, buy: Number(buyRate), sell: Number(sellRate), }); }); return rates; } }