Advertisement
Guest User

Formanowicz.js

a guest
Feb 10th, 2018
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const nodemailer = require('nodemailer');
  2. const request = require('request');
  3.  
  4. var transporter = nodemailer.createTransport({
  5.         host: 'smtp.gmail.com',
  6.         port: 587,
  7.         secure: false,
  8.         auth: {
  9.             user: 'login',
  10.             pass: 'password'
  11.         }
  12.     });
  13.  
  14.     var mailOptions = {
  15.         from: '"Forman" <example@gmail.com>',
  16.         to: 'example@gmail.com',
  17.         subject: 'Wyniki egzaminu z matemayki dyskretnej',
  18.         html: '<a>http://www.cs.put.poznan.pl/pformanowicz/students.html</a>'
  19.     };
  20.  
  21.     function notify()
  22.     {
  23.       transporter.sendMail(mailOptions, (error, info) => {
  24.           if (error) {
  25.               return console.log(error);
  26.           }
  27.           console.log(`Mail sent to ${mailOptions.to}`);
  28.  
  29.       });
  30.     }
  31.  
  32.     const options = {
  33.     url: 'http://www.cs.put.poznan.pl/pformanowicz/students.html',
  34.     method: 'HEAD'
  35.     };
  36.  
  37.     var lastModified;
  38.     request(options, (err, res, body)=>{
  39.         lastModified = res.headers['last-modified'];
  40.     });
  41.  
  42.  
  43.  
  44.     var id = setInterval(()=>{
  45.           var tmp;
  46.           request(options, (err, res, body)=>{
  47.               tmp = res.headers['last-modified'];
  48.               console.log("request made");
  49.  
  50.               if(lastModified != tmp)
  51.               {
  52.                 notify();
  53.                 clearInterval(id);
  54.               }
  55.           });
  56.  
  57.     }, 5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement