-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
50 lines (41 loc) · 1.16 KB
/
util.py
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
import time
import itchat
from selenium import webdriver
def capture(url, save_fn="tensorboard.png"):
browser = webdriver.Firefox() # Get local session of firefox
browser.set_window_size(1920, 1080)
browser.get(url) # Load page
browser.execute_script("""
(function () {
var y = 0;
var step = 100;
window.scroll(0, 0);
function f() {
if (y < document.body.scrollHeight) {
y += step;
window.scroll(0, y);
setTimeout(f, 50);
} else {
window.scroll(0, 0);
document.title += "scroll-done";
}
}
setTimeout(f, 1000);
})();
""")
for i in range(30):
if "scroll-done" in browser.title:
break
time.sleep(1)
browser.save_screenshot(save_fn)
browser.close()
def wechat_display():
@itchat.msg_register([itchat.content.TEXT])
def chat_trigger(msg):
if msg['Text'] == u'tensorboard':
capture("http://127.0.0.1:6006/")
itchat.send_image('tensorboard.png', 'filehelper')
itchat.auto_login(hotReload=True)
itchat.run()
if __name__ == '__main__':
wechat_display()