SHARE
TWEET

Untitled

a guest Apr 26th, 2018 19 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var path = require('path')
  2. const {exec} = require('child_process');
  3. var axios = require('axios');
  4. var listingUrl = process.argv[2];
  5. axios.get(listingUrl)
  6.         .then(function (response)
  7.         {
  8.             var sites = JSON.parse(data);
  9.             (async () => {
  10.                 const resizedImagePromises = sites.map(async site => {
  11.                     const screenshot = await getScreenshotFromUrl(site);
  12.                     const resizedScreenshot = await resizeScreenshot(site.outputImage);
  13.  
  14.                     return resizedScreenshot;
  15.                 });
  16.  
  17.                 const resizedImages = await Promise.all(resizedImagePromises);
  18.  
  19.             })();
  20.         })
  21.         .catch(function (error)
  22.         {
  23.             console.log(error);
  24.         });
  25.  
  26. function getScreenshotFromUrl(site)
  27. {
  28.     const browser = await puppeteer.launch();
  29.     const page = await browser.newPage();
  30.     await page.goto(site.siteUrl);
  31.     await page.setViewport({width: 1520, height: 1080});
  32.     await page.screenshot({path: site.outputImage});
  33.     await browser.close();
  34. }
  35.  
  36. function resizeScreenshot(outputImage)
  37. {
  38.     exec(`convert ${outputImage} -resize 200x200 ${outputImage}`, (err, stdout, stderr) => {
  39.         if (err)
  40.         {
  41.             console.log(`error on convert ${outputImage}`);
  42.             return;
  43.         }
  44.     });
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top