Initial working commit

This commit is contained in:
110Percent 2023-10-10 12:44:30 -04:00
parent 55781daffd
commit 3d0dff75c2
6 changed files with 2341 additions and 0 deletions

25
.eslintrc.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
env: {
es2021: true
},
extends: 'standard',
overrides: [
{
env: {
node: true
},
files: [
'.eslintrc.{js,cjs}'
],
parserOptions: {
sourceType: 'script'
}
}
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
rules: {
}
}

1
.gitignore vendored
View File

@ -130,3 +130,4 @@ dist
.yarn/install-state.gz
.pnp.*
config.json

8
config-example.json Normal file
View File

@ -0,0 +1,8 @@
{
"libcalUrl": "",
"roomName": "",
"bookingTime": "",
"firstName": "",
"lastName": "",
"email": ""
}

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "libcal-bot",
"repository": "git@ssh.gitdab.com:110Percent/libcal-bot.git",
"author": "110Percent <110percent@riseup.net>",
"license": "AGPL-3",
"devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.92",
"eslint": "^8.0.1",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-promise": "^6.0.0"
},
"scripts": {
"build": "npx swc ./src -d ./dist",
"start": "node ./dist/main.js"
},
"dependencies": {
"selenium-webdriver": "^4.14.0"
}
}

48
src/main.js Normal file
View File

@ -0,0 +1,48 @@
const { Builder, Browser, By, Key, until, Select } = require('selenium-webdriver')
const config = require('../config.json');
(async () => {
const driver = await new Builder().forBrowser(Browser.FIREFOX).build()
try {
await driver.manage().setTimeouts({ implicit: 2000 })
await driver.get(config.libcalUrl)
// Pick the proper date
await driver.findElement(By.className('fc-goToDate-button')).click()
await driver.wait(until.elementIsVisible(driver.findElement(By.className('datepicker-days'))))
await driver.actions().sendKeys(Key.ARROW_DOWN).sendKeys(Key.RETURN).perform()
// Pick the correct date cell
const bookingCell = await driver.findElement(By.xpath(`//*[starts-with(@title, '${config.bookingTime}') and contains(@title,'- ${config.roomName} -')]`))
await bookingCell.click()
// Pick the longest available booking time
const dateSelectElement = await driver.findElement(By.className('b-end-date'))
const dateSelect = new Select(dateSelectElement)
await dateSelectElement.click()
const options = await dateSelect.getOptions()
await options[options.length - 1].click()
// Submit time
const submitButton = await driver.findElement(By.id('submit_times'))
await submitButton.click()
// Continue
const termsButton = await driver.findElement(By.id('terms_accept'))
await termsButton.click()
// Fill in name
await driver.wait(until.elementIsVisible(driver.findElement(By.id('fname'))))
await driver.findElement(By.id('fname')).sendKeys(config.firstName)
await driver.findElement(By.id('lname')).sendKeys(config.lastName)
await driver.findElement(By.id('email')).sendKeys(config.email)
// Submit booking
await driver.findElement(By.id('btn-form-submit')).click()
// Pause
await driver.sleep(20000)
} finally {
await driver.quit()
}
})()

2237
yarn.lock Normal file

File diff suppressed because it is too large Load Diff