Skip to content

Instantly share code, notes, and snippets.

@viveksoundrapandi
Last active August 27, 2019 13:08
Show Gist options
  • Save viveksoundrapandi/e291081cab117dec42c02d8e75be566e to your computer and use it in GitHub Desktop.
Save viveksoundrapandi/e291081cab117dec42c02d8e75be566e to your computer and use it in GitHub Desktop.
Jazz cinemas ticket booking automation with puppeteer
const puppeteer = require('puppeteer');
// Entry point to begin the flow
const scrapeImages = async (movie_details) => {
console.log(`Initiating ticket booking for ${movie_details.username}`);
// launch the chrome broser
const browser = await puppeteer.launch( { headless: false, dumpio: true, args: ['--no-sandbox']});
// Open a new Tab
const page = await browser.newPage();
// Visit our target website
await page.goto('https://www.jazzcinemas.com/Customer/Login');
// Login to form by locating the DOM elements
await page.type('#login-username', movie_details.username);
await page.type('#login-password', movie_details.password);
await page.click('#btn-login');
// Wait for page load
await page.waitFor(3000);
//Inject custom scripts
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.2.1.min.js'});
//Select movie
await page.click('#Selectmovie');
await page.waitFor(1000);
await page.evaluate((movie_details) => {
$(`#ulmovielist span:contains(${movie_details.movie.name})`).click();
}, movie_details);
await page.waitFor(1000);
//Select number of tickets
await page.evaluate((movie_details) => {
$("#ulticketlist li").eq(movie_details.movie.tickets-1).click();
}, movie_details);
await page.waitFor(1000);
//Select show date
await page.evaluate((movie_details) => {
$(`#uldatelist li:contains(${movie_details.movie.date})`).click();
}, movie_details);
await page.waitFor(1000);
// Pick screens in desired time zone
await page.evaluate((movie) => {
let show_map = {};
let start_time = (new Date(`${movie.date} ${movie.time[0]}:00`)).getTime();
let end_time = (new Date(`${movie.date} ${movie.time[1]}:00`)).getTime();
let matched_show_times = $(".show-times .ShowList").filter(function(i, show){
let show_timestamp = (new Date(`${movie.date} ${$(show).text()}`)).getTime();
show_map[$(show).data("ontime")] = show_timestamp;
return (start_time <= show_timestamp) && (show_timestamp <= end_time);
});
matched_show_times[0].click();
}, movie_details.movie);
await page.waitFor(1000);
//Select best zone available Seats
await page.evaluate((movie) => {
let preferredRow = [3,4,5,6,7];
let preferredCol = [10,11,12,13,14,15,16];
let seatToSelect = movie.tickets;
let seatSelected;
preferredRow.forEach((row)=>{
preferredCol.forEach((col)=>{
seatSelected = $(`.seat-table [ticketid="0000000014|1|${row}|${col}"]`);
if(seatSelected.hasClass("Available")){
seatSelected.find('img').click();
seatToSelect--;
if(seatToSelect==0){
return false;
}
}
});
});
if(seatToSelect>0){
console.log("No AVAILABLE SEATS!");
throw new Error("No AVAILABLE SEATS!");
}
}, movie_details.movie);
await page.waitFor(1000);
await page.evaluate(() => {
$("#Proceed").click()
});
await page.waitFor(2000);
await page.evaluate(() => {
$("#FoodProce").click()
});
await page.waitFor(5000);
//FILL CARD DETAILS
await page.evaluate(() => {
$("#PaymentProcess li").eq(2).find('a span').click()
});
await page.waitFor(5000);
await page.screenshot({path: '1.png', fullPage: true});
await page.evaluate(() => {
$("#SCCardNumber").val("testuserUPI");
});
await page.waitFor(1000);
await page.screenshot({path: 'ticket.png', fullPage: true});
console.log(`Done ticket booking for ${movie_details.username}`);
}
scrapeImages({username:"******@gmail.com", password:"******", movie:{name: "BAKRID", tickets: 2, date:"24 Aug 2019", time:[9, 19]}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment