Victor Mouradian
03/30/2022, 12:39 PMVictor Mouradian
03/30/2022, 2:40 PMVictor Mouradian
03/30/2022, 2:40 PMconst puppeteer = require('puppeteer');
CAL_URL = "<your calendso url>"
async function login(page, username, password) {
await page.type('#email', username)
await page.type('#password', password)
await page.keyboard.press('Enter');
await page.waitForNavigation({
waitUntil: "networkidle2"
})
}
async function flow(page){
if(page.url() == CAL_URL+'/getting-started') {
await page.click('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button')
await page.waitForSelector('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button:nth-child(1)')
await page.click('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button:nth-child(1)')
await page.waitForSelector('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button:nth-child(1)')
await page.click('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button:nth-child(1)')
await page.waitForSelector('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button:nth-child(1)')
await page.click('#__next > div > div > article > section.max-w-xl.py-8.mx-auto > div > button:nth-child(1)')
await page.waitForNavigation()
} else {
return
}
}
async function doCalendso(user) {
return new Promise(async (resolve, reject) => {
const browser = await puppeteer.launch({
headless: true,
slowMo: 20,
browserContext: 'incognito'
});
page = await browser.newPage()
await page.goto(CAL_URL, { waitUntil: 'domcontentloaded' })
await login(page, user.username, user.password)
await flow(page)
await browser.close().then(() => {
resolve()
})
})
}
async function acceptGettingStarted(Calendso_user_list) {
for(const user of Calendso_user_list){
await doCalendso(user)
console.log("DONE : ")
console.log(user)
}
}
async function readfile(filepath) {
const fs = require('fs')
let userList = []
const file = fs.readFileSync(filepath, 'utf8')
file.split('\n').forEach(line => {
if(line != ""){
const user = {
username: line.split(',')[0],
password: line.split(',')[1].split('\r')[0]
}
userList.push(user)
}
})
return userList
}
async function main() {
// csv username, password
const userList = await readfile('cal.csv')
await acceptGettingStarted(userList)
}
main()