-
Notifications
You must be signed in to change notification settings - Fork 1
/
wg_updater.js
65 lines (56 loc) · 1.72 KB
/
wg_updater.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const chrome = require("selenium-webdriver/chrome");
const { By, Key, Builder } = require("selenium-webdriver");
var config = require("./settings/config.js");
const screen = {
width: 640,
height: 480,
};
async function update_offer(interval) {
let options = new chrome.Options();
options.addArguments("--headless=new");
options.addArguments("--window-size=640,480");
let driver = new Builder()
.forBrowser("chrome")
.setChromeOptions(options)
.build();
await driver.get("http://www.wg-gesucht.de");
try {
await driver.findElement(By.id("cmpbntyestxt")).click();
} catch (err) {
console.log("No cookie banner found");
}
try {
await driver.executeScript(
() => {
document.getElementById("login_email_username").value = arguments[0];
document.getElementById("login_password").value = arguments[1];
document.getElementById("login_submit").click();
},
config.login.username,
config.login.password
);
} catch (err) {
console.log("Login failed");
}
await driver.sleep(5000).then(console.log("Login successful!"));
await driver.get(
"https://www.wg-gesucht.de/angebot-bearbeiten.html?action=update_offer&offer_id=" +
config.offer.id
);
await driver.sleep(5000).then(console.log("WG-Gesucht ad loaded!"));
while (true) {
await driver.executeScript(() => {
document.getElementById("update_offer_nav").click();
});
console.log(
"Ad last updated on: " +
new Date(Date.now()).toLocaleString("de-DE", {
timeZone: "Europe/Berlin",
})
);
await driver.sleep(interval).then(() => {
console.log("Ad is being updated...");
});
}
}
update_offer(config.offer.interval * 60000);