Created
January 13, 2023 13:00
-
-
Save tae0y/c0dac9bf3a9cdd40a47c232a875e5eeb to your computer and use it in GitHub Desktop.
imax-finder_v230113
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
const nodemailer = require('nodemailer'); | |
const transporter = nodemailer.createTransport({ | |
service: 'gmail', | |
auth: { | |
user: '<메일주소>', | |
pass: '<메일비밀번호 또는 앱토큰>' | |
} | |
}); | |
const sendMail = image => { | |
const mailOptions = { | |
from: '<메일주소 - 보내는사람>', | |
to: '<메일주소 - 받는사람>', | |
subject: '영화예매!!', | |
text: `빨리 예매하세요!`, | |
attachments: [{ | |
path: `./screenshot/${image}.png` | |
}] | |
}; | |
transporter.sendMail(mailOptions, function (error, info) { | |
if (error) { | |
console.log(error); | |
} else { | |
console.log('Email sent: ' + info.response); | |
} | |
}); | |
} | |
const visitHomepage = async () => { | |
const config = { | |
title: '아바타-물의 길', | |
areacode: 01, | |
theaterCode: 0199, | |
date: 20230119 | |
} | |
const browser = await puppeteer.launch({ | |
headless: false | |
}); | |
const page = await browser.newPage(); | |
page.on('dialog', async dialog => { | |
await dialog.dismiss(); | |
}); | |
try { | |
await page.setViewport({ | |
width: 1280, | |
height: 720 | |
}); | |
const url = `http://www.cgv.co.kr/reserve/show-times/?`; | |
url += (`areacode=` + config.areacode); | |
url += (`&theaterCode=` + config.theaterCode); | |
url += (`&date=` + config.date); | |
await page.goto(url); | |
await page.waitForTimeout(1000); | |
const moviesNums = await page.evaluate(()=>{ | |
return document.getElementById('ifrm_movie_time_table').contentWindow.document.querySelectorAll('div.info-movie > a > strong').length; | |
}); | |
let isStop = false; | |
for (let i = 1; i < moviesNums; i++){ | |
const movieTitle = await page.evaluate((i)=>{ | |
return document.getElementById('ifrm_movie_time_table').contentWindow.document.querySelectorAll('div.info-movie > a > strong')[i].innerText; | |
}, i); | |
console.log(movieTitle); | |
if(movieTitle === config.title){ | |
isStop = true; | |
console.log('예매하세요!'); | |
const image = Date.now(); | |
await page.screenshot({path: `./screenshot/${image}.png`, fullPage: true}); | |
sendMail(image); | |
} | |
} | |
return browser.close(); | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
//var interval = setInterval(visitHomepage, 600000); | |
visitHomepage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
사용방법
코드내용
저는 절전모드를 끄고 작업스케줄러로 명령어 실행시켰습니다.
더 좋은 방법이 있을까요?