Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
·
f834da2
1
Parent(s):
c7f1171
kill old screenshot code
Browse files- python/screenshot.py +0 -57
python/screenshot.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
#
|
| 3 |
-
import os
|
| 4 |
-
import math
|
| 5 |
-
import socket
|
| 6 |
-
|
| 7 |
-
from selenium import webdriver
|
| 8 |
-
from selenium.webdriver.common.keys import Keys
|
| 9 |
-
from selenium.webdriver.common.by import By
|
| 10 |
-
|
| 11 |
-
from common import selectors
|
| 12 |
-
from entity import Entity
|
| 13 |
-
from common import defaults,mkdir
|
| 14 |
-
from imtool import coord_dict_to_point
|
| 15 |
-
|
| 16 |
-
options = webdriver.FirefoxOptions()
|
| 17 |
-
options.add_argument("--headless")
|
| 18 |
-
options.add_argument("--window-size=1920x8000")
|
| 19 |
-
options.set_preference('WebglAllowWindowsNativeGl', True)
|
| 20 |
-
|
| 21 |
-
host = os.getenv('GECKO_HOST') or 'localhost'
|
| 22 |
-
port = os.getenv('GECKO_PORT') or '4444'
|
| 23 |
-
ip = socket.gethostbyname(host)
|
| 24 |
-
|
| 25 |
-
print(f'host: {host}->{ip}, port: {port}')
|
| 26 |
-
|
| 27 |
-
driver = webdriver.Remote(
|
| 28 |
-
options=options,
|
| 29 |
-
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX,
|
| 30 |
-
command_executor=f"http://{ip}:{port}"
|
| 31 |
-
)
|
| 32 |
-
def sc_entity(e: Entity):
|
| 33 |
-
print(f'screenshoting: {e}')
|
| 34 |
-
mkdir.make_dirs([
|
| 35 |
-
defaults.IMAGES_PATH,
|
| 36 |
-
defaults.LABELS_PATH,
|
| 37 |
-
])
|
| 38 |
-
|
| 39 |
-
driver.implicitly_wait(10)
|
| 40 |
-
driver.get(e.url)
|
| 41 |
-
#driver.save_screenshot(f"{defaults.DATA_PATH}/{e.bco}.png")
|
| 42 |
-
|
| 43 |
-
p = f"{defaults.IMAGES_PATH}/{e.bco}.full.png"
|
| 44 |
-
html = driver.find_element(By.TAG_NAME, 'html')
|
| 45 |
-
# driver.save_screenshot(p)
|
| 46 |
-
html.screenshot(p)
|
| 47 |
-
print(f'wrote: {p}')
|
| 48 |
-
|
| 49 |
-
logos = driver.find_elements(By.CSS_SELECTOR, selectors.img_logo) or []
|
| 50 |
-
logos.extend(driver.find_elements(By.CSS_SELECTOR, selectors.id_logo) or [])
|
| 51 |
-
logos.extend(driver.find_elements(By.CSS_SELECTOR, selectors.cls_logo) or [])
|
| 52 |
-
with open(f"{defaults.LABELS_PATH}/{e.bco}.full.txt", 'w') as f:
|
| 53 |
-
for i in logos:
|
| 54 |
-
f.write(f"{e.id} {coord_dict_to_point(i.rect)}\n")
|
| 55 |
-
|
| 56 |
-
if __name__ == '__main__':
|
| 57 |
-
sc_entity(Entity.from_dict({'url': 'http://www.bbva.com.ar', 'bco': 'debug'}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|