Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const nodemailer = require('nodemailer');
- const request = require('request');
- const cp = require('child_process');
- const rick = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
- const forman = 'http://www.cs.put.poznan.pl/pformanowicz/students.html';
- function getLogString()
- {
- var date = new Date();
- return '[' + date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()+'] ';
- }
- var transporter = nodemailer.createTransport({
- host: 'smtp.gmail.com',
- port: 587,
- secure: false,
- auth: {
- user: 'username',
- pass: 'password'
- }
- });
- var mailOptions = {
- from: '"It\'s Piotr Formanowicz!" <michal.sw12@gmail.com>',
- to: 'address',
- subject: 'Wyniki egzaminu z matemayki dyskretnej',
- html: `<a href="${forman}">${forman}</a>`
- };
- function notify()
- {
- transporter.sendMail(mailOptions, (error, info) => {
- if (error) {
- return console.log(error);
- }
- console.log(getLogString()+`Mail sent to ${mailOptions.to}`);
- });
- }
- const options = {
- url: forman,
- method: 'HEAD'
- };
- console.log(getLogString() + "forman.js started");
- var lastModified;
- console.log(getLogString() + "Establishing connection...");
- request(options, (err, res, body)=>{
- if(err) {console.log(getLogString()+ 'Could not establish a connection, exiting...'); process.exit(1);};
- lastModified = res.headers['last-modified'];
- console.log(getLogString() +'Site last modified on ' + lastModified);
- });
- var id = setInterval(()=>{
- var tmp;
- request(options, (err, res, body)=>{
- if(err) return console.log(getLogString() + ' Connection lost, trying again...');
- tmp = res.headers['last-modified'];
- if(lastModified != tmp)
- {
- notify();
- cp.spawn('C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', [rick, forman]);
- clearInterval(id);
- console.log(getLogString()+"Exiting...");
- }
- });
- }, 5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement