const selenium = require('selenium-webdriver'); const pg = require('pg'); const client = new pg.Client({ database:"outcomes_tracker" }) const delay = (ms) => { return new Promise((resolve) => { setTimeout(resolve, ms); }); } let driver; const myInstanceIDs = [200339, 199169, 197195, 195883, 194294, 188057, 181297]; const login = async ()=> { driver = await new selenium.Builder().forBrowser('chrome').build(); await driver.get('https://outcomes.generalassemb.ly/'); let selection = selenium.By.id('identify_email'); let element = await driver.findElement(selection); element.sendKeys('matt.huntington@generalassemb.ly'); selection = selenium.By.id('baseForm'); element = await driver.findElement(selection); element.submit(); await delay(2000); selection= selenium.By.css('input[type="text"]'); element = await driver.findElement(selection); element.sendKeys('matt.huntington@generalassemb.ly'); selection= selenium.By.css('input[type="password"]'); element = await driver.findElement(selection); element.sendKeys('Hunt!ngt0n80!'); selection = selenium.By.css('form'); element = await driver.findElement(selection); element.submit(); await delay(2000); selection= selenium.By.css('a') let elements = await driver.findElements(selection); elements[1].click(); } const search = async () => { let selection = selenium.By.id('program'); let element = await driver.findElement(selection); let select = new selenium.Select(element); await select.selectByVisibleText('Software Engineering Immersive Remote'); selection = selenium.By.id('metro'); element = await driver.findElement(selection); select = new selenium.Select(element); await select.selectByVisibleText('Online'); selection = selenium.By.id('from'); element = await driver.findElement(selection); element.sendKeys('01/01/2021'); selection = selenium.By.id('filter-form'); element = await driver.findElement(selection); element.submit(); } const main = async () => { await client.connect(); const res = await client.query('SELECT $1::text as message', ['Connected to Postgres']) console.log(res.rows[0].message) // Hello world! await login(); await delay(8000); await search(); await delay(2000); let selection = selenium.By.css('table td>a'); let elements = await driver.findElements(selection); for(currentElement of elements){ currentElement.click(); await delay(3000); try{ selection = selenium.By.css('.full-time-90-days-actuals'); let element = await driver.findElement(selection); let innerHTML = await element.getAttribute('innerHTML'); const percent = parseInt(innerHTML.match(/([0-9]*%)/)[0].replace('%','')) const url = await driver.getCurrentUrl(); const instanceID = parseInt(url.match(/[0-9]*$/i)[0]); selection = selenium.By.css('p.course-header__detail'); element = await driver.findElement(selection); innerHTML = await element.getAttribute('innerHTML'); const graduationDateString = innerHTML.split(' - ')[1].trim(); //const graduationDate = new Date(graduationDateString); if(myInstanceIDs.includes(instanceID)){ console.log("me -->", instanceID, graduationDateString, percent); } else { console.log(instanceID, graduationDateString, percent); } const res = await client.query(`INSERT INTO instances (instance_id, graduation_date, ninety_day_outcomes) VALUES (${instanceID}, '${graduationDateString}', ${percent})`); } catch (error) { console.log(error); } await driver.navigate().back(); } } main()