baruchhersh

bank

Mar 24th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const app = require('express')()
  2. const { createScraper } = require('israeli-bank-scrapers');
  3. const fetch = require(`node-fetch`);
  4. const cors = require(`cors`);
  5. const hook = `https://hook.integromat.com/urlny1m9oce71e1mcxmjfszebfdrtb3o`
  6.  
  7. const credentialsArr = [
  8.     {
  9.         userCode: "",
  10.         password: ""
  11.     },
  12.     {
  13.         username: "",
  14.         password: ""
  15.     },
  16.     {
  17.         id: "",
  18.         password: "",
  19.         num: ""
  20.     }
  21. ]
  22.  
  23.  
  24. app.use(require('express').json())
  25. app.use(cors())
  26.  
  27. app.post('/bank', async function (req, res) {
  28.     try {
  29.         let credentials = {}
  30.         switch (req.body.bank) {
  31.             case "hapoalim":
  32.                 credentials = credentialsArr[0]
  33.                 credentials.userCode = req.body.userCode
  34.                 credentials.password = req.body.password
  35.                 break;
  36.             case "leumi":
  37.             case "mizrahi":
  38.             case "otsarHahayal":
  39.                 credentials = credentialsArr[1]
  40.                 credentials.username = req.body.username
  41.                 credentials.password = req.body.password
  42.                 break;
  43.             case "discount":
  44.                 credentials = credentialsArr[2]
  45.                 credentials.password = req.body.password
  46.                 credentials.id = req.body.id
  47.                 credentials.num = req.body.num
  48.                 break;
  49.  
  50.             default:
  51.                 break;
  52.         }
  53.         const options = {
  54.             companyId: req.body.bank, // mandatory; one of 'hapoalim', 'hapoalimBeOnline', leumi', 'discount', 'mizrahi', 'otsarHahayal', 'visaCal', 'max', 'isracard', 'amex'
  55.             startDate: new Date(req.body.year, req.body.month + 1, req.body.day + 1), // the date to fetch transactions from (can't be before the minimum allowed time difference for the scraper)
  56.             combineInstallments: `true`, // if set to true, all installment transactions will be combine into the first one
  57.             showBrowser: `true`, // shows the browser while scraping, good for debugging (default false)
  58.             verbose: `true`, // include more debug info about in the output
  59.             //browser : Browser, // optional option from init puppeteer browser instance outside the libary scope. you can get browser diretly from puppeteer via `puppeteer.launch()` command.
  60.             //executablePath: string // optional. provide a patch to local chromium to be used by puppeteer. Relevant when using `israeli-bank-scrapers-core` library
  61.         };
  62.  
  63.         const scraper = createScraper(options);
  64.         const scrapeResult = await scraper.scrape(credentials);
  65.  
  66.         if (scrapeResult.success) {
  67.            res.send(scrapeResult);
  68.         // await
  69.         //  fetch(hook, {
  70.         //  method: 'POST',
  71.         //  headers: {
  72.         //  'Content-Type': 'application/json'
  73.         //   },
  74.         //   body: JSON.stringify(scrapeResult),
  75.         //   });
  76.         }
  77.         else {
  78.             res.send(500);
  79.         }
  80.     } catch (e) {
  81.         console.error(`scraping failed for the following reason: ${e.message}`);
  82.     }
  83. })
  84.  
  85. app.listen(1000, function () {
  86.  
  87. })
Add Comment
Please, Sign In to add comment