From f847b3d5246d805ebfb762cb5c2deed62bb3ba76 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Thu, 23 Mar 2017 17:45:01 +0100 Subject: [PATCH] initial commit add selenium for smartfact image grabbing --- la_palma_overview/__init__.py | 31 +++++++++++++++++++++++++------ setup.py | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/la_palma_overview/__init__.py b/la_palma_overview/__init__.py index 9e4a364..e860eb5 100644 --- a/la_palma_overview/__init__.py +++ b/la_palma_overview/__init__.py @@ -27,10 +27,12 @@ import requests import logging import warnings +import time from multiprocessing.pool import ThreadPool from .log import setup_logging +from selenium import webdriver __all__ = ['save_image'] @@ -220,11 +222,24 @@ def download_and_resize_image(url, rows, cols, fmt='jpg', fallback=True): log.debug('Downloaded image from url {}'.format(url)) except Exception as e: - if fallback is True: - log.exception('Failed to get image for url {}'.format(url)) - img = empty_image(rows, cols) - else: - raise IOError from e + try: + driver = webdriver.PhantomJS() + driver.set_window_size(cols, int(rows*1.4)) + driver.get(url) + # sleep 2 seconds to + # allow javascript to load the image data and render it + # 2 seconds is just a guess. + time.sleep(2) + img = skimage.io.imread(io.BytesIO(driver.get_screenshot_as_png())) + img = img[-rows:, -cols:, :3] + + log.debug('Downloaded with PhatomJS from url {}'.format(url)) + except Exception as e: + if fallback is True: + log.exception('Failed to get image for url {}'.format(url)) + img = empty_image(rows, cols) + else: + raise IOError from e return img @@ -273,8 +288,12 @@ def save_image(output_path, overview_config=None): if cfg is None: cfg = { 'img': {'rows': 480, 'cols': 640}, - 'stacked_image': {'rows': 3, 'cols': 4}, + 'stacked_image': {'rows': 4, 'cols': 4}, 'image_urls': [ + 'http://fact-project.org/smartfact/index.html?sound#current', + 'http://fact-project.org/smartfact/index.html?sound#thresholds-patch', + 'http://fact-project.org/smartfact/index.html?sound#camtemp', + 'http://fact-project.org/smartfact/index.html?sound#fact', 'http://fact-project.org/cam/skycam.php', 'http://www.gtc.iac.es/multimedia/netcam/camaraAllSky.jpg', 'http://www.magic.iac.es/site/weather/AllSkyCurrentImage.JPG', diff --git a/setup.py b/setup.py index e3526cc..4eb9d5e 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,7 @@ 'requests', 'smart_fact_crawler==0.3.1', 'send2trash', + 'selenium', ], entry_points={'console_scripts': [ 'la_palma_overview = la_palma_overview.__init__:main',