def cli(ctx: click.Context, verbose: int, db_name: str): init_logging() _log.setLevel(DEBUG if verbose else INFO) if verbose > 1: parent_package = '.'.join(__package__.split('.')[:-1]) log = get_logger(parent_package) log.setLevel(DEBUG if verbose else INFO) db_path = Path(db_name) if not (db_path.exists() and db_path.is_file()): raise click.BadOptionUsage( option_name='--db', message=f'"{db}" is not a file or does not exist...') dialect = 'sqlite:///' db_parent = db_path.parent url = f'{dialect}./{db_path}' if str( db_parent) == '.' else f'{dialect}{db_path}' ctx.obj = db.Database(url)
def run_server(host: str, port: int, initialize: bool, verbose: int): init_logging() log = get_logger(__package__) log.setLevel(DEBUG if verbose else INFO) log.info("Initializing REST Services...") init_stopwatch = StopWatch(label="Complete in", in_ms=False) from .api import weather_data_app, initialize_weather_data log.info(f'{init_stopwatch}.') if initialize: initialize_weather_data() log.info(f'Starting uvicorn') import uvicorn log_level = "trace" if verbose > 1 else "debug" if verbose else "info" uvicorn.run(weather_data_app, host=host, port=port, log_level=log_level, lifespan="on")
import weather.domain as wd import weather.server.auth as ws from weather import StopWatch from weather.configuration import get_logger from . import database as db, crud _log = get_logger(__name__) class WeatherDataLoader: def __init__(self, weather_data: wd.WeatherData = wd.WeatherData(), database: db.Database = db.Database()): self.weather_data = weather_data self.database = database self.get_session = database.get_session def load(self, users: bool = True, locations: bool = True, histories: bool = True, normalized_histories=True): _log.info("Starting database load...") self.load_permissions() if users: self.load_users() if locations: self.load_locations() if histories: self.load_histories() if normalized_histories:
from datetime import date, datetime, timedelta from logging import DEBUG, INFO from pathlib import Path from typing import Callable, Dict, Iterable, List, Tuple, TypeVar import click import pytz from sqlalchemy.orm import Session import weather.db as db import weather.domain as wd import weather.server as srvr from weather import StopWatch from weather.configuration import get_logger, get_setting, init_logging _log = get_logger(__package__) _default_db = "weather_data.db" _weather_data_dir = get_setting("domain", "weather_data_dir") @click.group("dbcli", context_settings=dict(help_option_names=['-h', '--help'])) @click.option('-v', 'verbose', count=True, help='Level of messaging from the cli (-v, -vv, etc.).') @click.option('--db', 'db_name', type=str, default=_default_db, help='The database name.',