Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 1. Add this file to a tests directory and name it netflix.js.
// 2. Create a docker container that mounts that directory
// docker run -it -d --name casper2 -v /mnt/user/tests:/tests rdpanek/casperjs bin/bash
// 3. Set up an hourly cron job by creating a new file
// #!/bin/bash
// docker exec casper2 casperjs /tests/netflix.js
// Then add a command to /etc/cron.hourly/speedtest to run this script in the container and chmod +x that file.
var casper = require('casper').create();
casper.options.waitTimeout = 120000;
var speed = 1;
var units;
casper.start('https://fast.com/', function() {
this.echo(this.getTitle());
});
casper.waitForSelector('.succeeded', function() {
speed = this.getHTML('div#speed-value');
units = this.getHTML('div#speed-units');
this.echo(speed + " " + units);
casper.thenOpen('https://maker.ifttt.com/trigger/USEYOUROWNKEY!', {
method: 'post',
data: {
'value1': speed,
'value2': units,
'value3': "home"
}
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment