Skip to content

Instantly share code, notes, and snippets.

@jakswa
Last active May 15, 2020 16:31
Show Gist options
  • Save jakswa/ed367e1105ac7b2a62c400c55af56391 to your computer and use it in GitHub Desktop.
Save jakswa/ed367e1105ac7b2a62c400c55af56391 to your computer and use it in GitHub Desktop.
This is my weekly 15five script.

This is my weekly 15five script.

to run: npx <this browser URL>

early version example:

$ FIVE15UN="<username>" FIVE15PW='<password>' npx https://gist.github.com/jakswa/ed367e1105ac7b2a62c400c55af56391
logging in as: <username>
Found form. Let's get you sorted!
happiness=4
marked complete
goal for next week: code
devoted 8/10
Submitting...
...Now tho. Submit now.
great job!
#!/usr/bin/env node
const { firefox } = require('playwright');
const util = require('util');
const setTimeoutPromise = util.promisify(setTimeout);
(async () => {
if (!process.env.FIVE15UN || !process.env.FIVE15PW) {
console.log("env vars FIVE15UN & FIVE15PW are required. exiting.");
return;
}
const browser = await firefox.launch();//{ headless: false });
const page = await browser.newPage();
await page.goto('https://my.15five.com/?next=/report/current/');
console.log("waiting for login page...");
await page.waitForSelector('input[name=username]');
// login step
console.log(`logging in as: ${process.env.FIVE15UN}`);
await page.fill('input[name=username]', process.env.FIVE15UN);
await page.fill('input[name=password]', process.env.FIVE15PW);
await page.click('button[type=submit]');
// wait for page to be ready
await page.waitForSelector('text=Mark priorities', { timeout: 3000 });
if (await page.$('#fillout-report-form')) {
console.log("Found form. Let's get you sorted!");
await fillOut15Five(page);
} else {
console.log("No form. You already submitted, I think. Bye.");
}
await setTimeoutPromise(1000);
await browser.close();
})();
async function fillOut15Five(page) {
await page.click('label[for="pulse-input-4"]');
console.log("happiness=4");
let complete = 'button[aria-label="Mark Complete"]';
if (await page.$(complete)) {
await page.click(complete);
}
console.log("marked complete");
let goal = '.current-goals textarea[placeholder="Add a new priority"]';
if (!await page.$(goal)) {
page.fill(goal, 'code');
}
console.log("goal for next week: code");
await page.click(".metric-range >> text=8");
console.log("devoted 8/10");
console.log("Submitting...");
let navwait = page.waitForNavigation();
await page.click('.js-submit-report >> text=ubmit');
// if early, there'll be 2nd
let submit2 = 'text=Submit now';
if (await page.waitForSelector(submit2, { timeout: 1000 })) {
page.click(submit2);
console.log("...Now tho. Submit now.");
}
await navwait;
console.log("great job!");
}
{"name": "auto15five", "version": "0.0.1", "bin": "./index.js", "dependencies": { "playwright": "^1.0.1" }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment