예제 #1
0
def get_capture(name, **kwargs):
    '''Return a cached Capture() object constructed with kwargs'''
    if name in _captures:
        return _captures[name]
    capture = _captures[name] = Capture(**kwargs)
    end_time, delay = time.time() + 10, 0.05
    logging.info('Waiting for capture.js...')
    while not capture.started:
        if time.time() > end_time:
            raise RuntimeError('capture.js took too long to start')
        time.sleep(delay)
    return capture
예제 #2
0
import os
import shutil
import logging
from gramex.handlers import Capture         # Import the capture library

capture = Capture(engine='chrome', port=9905, timeout=30)


def generator():
    cur_direc = os.path.dirname(os.path.abspath(__file__))
    spec_names = [spec_file.split('.vg.json')[0]
                  for spec_file in os.listdir(os.path.join(cur_direc, 'assets', 'specs'))]
    host = 'http://127.0.0.1:9988'

    images_dir = os.path.join(cur_direc, 'assets', 'images')
    for filename in os.listdir(images_dir):
        filepath = os.path.join(images_dir, filename)
        logging.warn("deleting: " + filename)
        try:
            shutil.rmtree(filepath)
        except OSError:
            os.remove(filepath)

    for spec_name in spec_names:
        logging.warn(os.path.join(cur_direc, 'assets',
                                  'images', spec_name + '.png'))
        with open(os.path.join(cur_direc, 'assets', 'images', spec_name + '.png'), 'wb') as f:
            url = host + '/example.html?delay=renderComplete&chart=' + spec_name
            f.write(capture.png(url, ext='png', selector='#chart svg'))

예제 #3
0
import os
import gramex.data
from io import BytesIO
from ast import literal_eval
from PIL import Image
from gramex.config import variables as var, app_log
from gramex.handlers import Capture
from gramex.http import NOT_FOUND
from gramex.services import info
from gramex.transforms import handler
from tornado.web import HTTPError
import pandas as pd

FOLDER = os.path.abspath(os.path.dirname(__file__))
TARGET = os.path.join(var.GRAMEXDATA, 'uifactory', 'thumbnail')
capture = Capture(engine='chrome')

if not os.path.exists(TARGET):
    os.makedirs(TARGET)


def modify_columns(handler, data):
    if handler.request.method == 'GET' and len(data):
        # create dataframe from data, filter responses for the current form
        df = pd.DataFrame(data)
        df = df[df['form_id'].astype('int') == int(handler.get_argument('db'))]
        if(df.shape[0] > 0):
            response = []
            for _, row in df.iterrows():
                response.append(
                    literal_eval(row['response'])