Last active
February 19, 2025 08:20
-
-
Save ZiTAL/5a1c74a84041e16cb0483368dd97a486 to your computer and use it in GitHub Desktop.
Kiroldegian "Fitness Funtzional" klase solteetan apuntatzeko script-a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mondays and wednesdays at 00:01 | |
1 0 * * 1,3 /home/pi/scripts/bash/ff.sh >> /dev/null 2>> /home/pi/scripts/bash/ff.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const { Selector, ClientFunction } = require('testcafe') | |
const url = "https://kirola.bermeokoudala.eus/buscGrupoLibre.php?tipo=0&tipc=3" | |
fixture `poli` | |
.page(url) | |
.beforeEach(async t => | |
{ | |
await t.resizeWindow(1920, 1080) | |
}) | |
test('Fitness Funtzionalerako sarrera erosi', async t => | |
{ | |
let config = process.env.CONFIG | |
config = fs.readFileSync(config, 'utf8') | |
config = JSON.parse(config) | |
const today = new Date() | |
let tomorrow = new Date(today) | |
tomorrow.setDate(today.getDate() + 1) | |
tomorrow = `${String(tomorrow.getDate()).padStart(2, '0')}/${String(tomorrow.getMonth() + 1).padStart(2, '0')}/${tomorrow.getFullYear()}` | |
// cookies | |
await t.wait(2000) | |
const cookies = Selector('#gdpr-cookie-accept') | |
await t.click(cookies) | |
// search | |
await t.wait(2000) | |
const botonbuscar = Selector('#botonbuscar') | |
await t.click(botonbuscar) | |
// list fitness classes | |
await t.wait(2000) | |
const ff = Selector('div.panel-heading > a > strong > div').withText('FITNESS FUNTZ') | |
const bd = ff.with({ boundTestRun: t }) | |
const bd_count = await bd.count | |
/* | |
Div 5 content: alert('***Ftope***18/02/2025') | |
Div 6 content: minilogin(' FF 002',0,'17/02/2025') | |
*/ | |
// get all classes from tomorrow | |
const divs = [] | |
for (let i = 0; i < bd_count; i++) | |
{ | |
const div = await bd.nth(i).parent('div').parent('div') | |
const ct = await div.getAttribute('onclick') | |
const a = new RegExp(tomorrow) | |
if(ct.match(a)) | |
divs.push(div) | |
} | |
// get the last one of the day | |
const div = divs.at(-1) | |
const ct = await div.getAttribute('onclick') | |
// check if is available | |
if(ct.match(/minilogin/)) | |
{ | |
await t.wait(1000) | |
const id = await div.getAttribute('id') | |
await t.click(div) | |
await t.wait(2000) | |
// set user and passwd | |
const user = Selector('#usuario') | |
await t.typeText(user, config['user']) | |
const passwd = Selector('#password') | |
await t.typeText(passwd, config['passwd']) | |
await t.wait(1000) | |
// login | |
const login = Selector('button').withAttribute('class', 'btn btn-success float-end') | |
await t.click(login) | |
await t.wait(5000) | |
// add to cart | |
const bres = Selector('#bres') | |
await t.click(bres) | |
await t.wait(5000) | |
// show cart | |
const cart = Selector('button').withAttribute('class', 'btn btn-success float-end') | |
await t.click(cart) | |
await t.wait(5000) | |
// buy | |
const bcomprar = Selector('#bcomprar') | |
await t.click(bcomprar) | |
await t.wait(5000) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CONFIG="/home/pi/scripts/node/zital.json" testcafe firefox:headless /home/pi/scripts/node/ff.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"user": "12345678A", | |
"passwd": "123456789" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
install testcafe