Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show also current in overview video? #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions la_palma_overview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down