File size: 701 Bytes
36ba3ef |
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 |
import os
import time
from selenium import webdriver
import utils as U
class VisualAPI:
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.set_window_size(320, 512)
def run(self):
self.driver.get("http://localhost:9000")
IMAGE_DIR = 'Adam/game_image'
U.f_mkdir(IMAGE_DIR)
if not os.path.exists(IMAGE_DIR):
os.makedirs(IMAGE_DIR)
print('Visual API Ready')
while True:
screenshot_path = os.path.join(IMAGE_DIR, 'tmp.png')
self.driver.save_screenshot(screenshot_path)
time.sleep(10)
def stop(self):
self.driver.quit()
module = VisualAPI()
module.run()
|