示例#1
0
def app(verbose, config_path, log_path, token_path):
    global cfg, google

    # Ensure paths are full paths
    if not config_path.startswith(os.path.sep):
        config_path = os.path.join(
            os.path.dirname(os.path.realpath(sys.argv[0])), config_path)
    if not log_path.startswith(os.path.sep):
        log_path = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
                                log_path)
    if not token_path.startswith(os.path.sep):
        token_path = os.path.join(
            os.path.dirname(os.path.realpath(sys.argv[0])), token_path)

    # Load config
    from utils.config import Config
    cfg = Config(config_path=config_path).cfg

    # Load logger
    log_levels = {0: 'INFO', 1: 'DEBUG', 2: 'TRACE'}
    log_level = log_levels[verbose] if verbose in log_levels else 'TRACE'
    config_logger = {
        'handlers': [{
            'sink': sys.stdout,
            'backtrace': True if verbose >= 2 else False,
            'level': log_level
        }, {
            'sink': log_path,
            'rotation': '30 days',
            'retention': '7 days',
            'enqueue': True,
            'backtrace': True if verbose >= 2 else False,
            'level': log_level
        }]
    }
    logger.configure(**config_logger)

    # Load google
    google = Google(cfg.client_id, cfg.client_secret, cfg.project_name,
                    token_path)

    # Display params
    logger.info("%s = %r" % ("LOG_PATH".ljust(12), log_path))
    logger.info("%s = %r" % ("LOG_LEVEL".ljust(12), log_level))
    logger.info("")
    return
示例#2
0
import dash_core_components as dcc
import plotly.graph_objs as go
import dash_table
from dash.dependencies import Input, Output
import pandas as pd

import app.template as template
from app.app import dash_app
from utils.google import Google

APPS_NAME = 'Promised Neverland Season 2'
g = Google()
df = g.get_data()
df['Date'] = pd.to_datetime(df['Date'])
df_table = df.copy()
df_table['Date'] = df_table['Date'].dt.strftime('%m/%d/%Y')
df_table = df_table.drop(columns=['Source'])


dropdown_menu = dcc.Dropdown(id='data-input-' + APPS_NAME,
                            options=[ {'label': 'MAL', 'value': 'Score'}],
                            value=['Score'],
                            multi=True)

table = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in df_table.columns],
    style_cell={'textAlign': 'center'},
    style_header={
        'backgroundColor': 'rgb(230, 230, 230)',
        'fontWeight': 'bold'