Exemple #1
0
    return logger


def log_except_hook(*exc_info):
    global logger
    text = "".join(traceback.format_exception(*exc_info))
    logger.error("Unhandled exception: %s", text)


def main():
    try:
        my_bibli.login()
        my_bibli.hydrate_books()
    except BaseException as error:
        logger.exception("Exception from hydrate_books")
    else:
        bibli_sync.sync(airtable, my_bibli.book_objects, logger)
    finally:
        my_bibli.close()


sys.excepthook = log_except_hook
env = pydotenv.Environment(check_file_exists=True)
airtable = Airtable(env.get('AIRTABLE_BASE_KEY'), 'books', api_key=env.get('AIRTABLE_API_KEY'))
logger = make_logger()
my_bibli = Bibli(env.get('CARD_NUMBER'), env.get('PASSWORD'), logger)

if __name__ == "__main__":
    main()
from pathlib import Path
import pydotenv
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env_path = BASE_DIR / '.env.dev'
env = pydotenv.Environment(file_path=env_path)


def _get_env(name, default):
    '''
    try to load env from pydotenv, if not available load from system ENV
    otherwise use the default
    '''
    return env.get(name, os.environ.get(name, default))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = _get_env('SECRET_KEY', '')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = _get_env('DEBUG', True)

ALLOWED_HOSTS = []

# Application definition
 def __init__(self):
     if Environment.__instance is not None:
         raise Exception('The class already have an instance')
     else:
         self.get = pydotenv.Environment()
         Environment.__instance = self
Exemple #4
0
# create database
import pydotenv
env = pydotenv.Environment()
from sqlaclchemy import create_engine
engine = create_engine('postgresql://*****:*****@localhost:5432/raj_db')
from app import db
db.create_all()