-
Notifications
You must be signed in to change notification settings - Fork 3
/
running_colab_iteratively.js
52 lines (41 loc) · 1.82 KB
/
running_colab_iteratively.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
//Sleep function
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
//Initiating iteration
var iteration = 0;
//Main function
const main = async () => {
if (iteration < 2){
//Click on connect button
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click();
//Wait for the VM to connect
await sleep(10000);
//Run script
document.querySelector("colab-run-button").click();
//Wait for the script to finish (you may change this)
await sleep(5000);
//Click on menu button
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect-button-resource-display > colab-usage-bar.disk").click();
await sleep(5000);
//Click on manage sessions
document.querySelector("body > div.notebook-vertical > div.notebook-horizontal > div.layout.vertical.grow > colab-tab-layout-container > colab-tab-pane > colab-resizer > div.layout.vertical.grow > iron-pages > colab-tab > colab-shaded-scroller > colab-usage-display").shadowRoot.querySelector("div:nth-child(4) > paper-button:nth-child(1)").click();
await sleep(5000);
//Click on terminate session
document.querySelector("body > colab-dialog > paper-dialog > colab-sessions-dialog").shadowRoot.querySelector("div.dialog-main-content > div.sessions-content.layout.vertical > div.dialog-table > colab-session > div.button-action-column > paper-button").click();
await sleep(2000);
//Click on okay buttom if prompted
try {
document.querySelector("#ok").click();
await sleep(2000);
}
catch(err) {
console.log('No okay button')
}
iteration ++;
}
}
//Run main function
main();
//Repeat main function iteratively every 30 seconds (you may change this)
setInterval(main,30000);