示例#1
0
 def test_get(self):
     os.environ['VALUE'] = '1'
     value = environ.get_bool('VALUE')
     self.assertTrue(value)
     os.environ['VALUE'] = '0'
     value = environ.get_bool('VALUE')
     self.assertFalse(value)
示例#2
0
    'PAGE_SIZE': 10
}

# telegram
TELEGRAM_BOT_TOKEN = easy_env.get('TELEGRAM_BOT_TOKEN', raise_error=True)
TELEGRAM_TIMEOUT = 30  # seconds

# celery
REDIS_URL = easy_env.get('REDIS_URL', 'redis://localhost:6379/0')
CELERY_BROKER_URL = REDIS_URL
CELERY_RESULT_BACKEND = REDIS_URL
CELERY_TASK_SERIALIZER = 'json'
CELERY_WORKER_CONCURRENCY = easy_env.get_int('CELERY_WORKER_CONCURRENCY',
                                             default=multiprocessing.cpu_count())
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
CELERY_REDIS_MAX_CONNECTIONS = 20

# core
TG_ADMINS = easy_env.get_list('ADMINS', [], item_factory=int)

# reddit
REDDIT_FETCH_SIZE = easy_env.get_int('REDDIT_FETCH_SIZE', default=100)

# imgur
IMGUR_CLIENT_ID = easy_env.get('IMGUR_CLIENT_ID')
IMGUR_FETCH_LIMIT = easy_env.get_int('IMGUR_FETCH_LIMIT', default=100)
IMGUR_DELETE_ON_FAIL = easy_env.get_bool('IMGUR_DELETE_ON_FAIL', default=True)

# rss
RSS_CLEAN_KEEP = easy_env.get_int('RSS_CLEAN_KEEP', default=30)
示例#3
0
import os
import re

import easy_env
from dotenv import find_dotenv, load_dotenv

load_dotenv(find_dotenv())

DEBUG = easy_env.get_bool('DEBUG', default=False)
USERBOT_NAME = easy_env.get('USERBOT_NAME', 'userbot')
REDIS_URL = easy_env.get_str('REDIS_URL')
API_ID = easy_env.get_int('API_ID', raise_error=True)
API_HASH = easy_env.get('API_HASH', raise_error=True)

USER_PHONE = easy_env.get('USER_PHONE')
USER_PASSWORD = easy_env.get('USER_PASSWORD')

NOU_LIST = easy_env.get_list('NOU_LIST', ['baka', 'idiot'], separator='|')
NOU_PATTERN = "|".join([f"\\b{w}\\b" for w in NOU_LIST])
NOU_PATTERN = f'.*({NOU_PATTERN}).*'
NOU_LIST_REGEX = re.compile(NOU_PATTERN, re.IGNORECASE)

NAME = easy_env.get('NAME', 'dude')
LOGS_FILE_PATH = easy_env.get('LOGS_FILE_PATH', 'logs.txt')
LOGS_FILE_DIR = os.path.split(LOGS_FILE_PATH)[0]
if LOGS_FILE_DIR:
    os.makedirs(LOGS_FILE_DIR, exist_ok=True)

LOGGING_LEVEL = easy_env.get('LOGGING_LEVEL', 'DEBUG')
LOGGING_LEVEL_ROOT = easy_env.get('LOGGING_LEVEL_ROOT', 'INFO')
示例#4
0
import logging.config
import multiprocessing
from os.path import dirname

import easy_env
from dotenv import find_dotenv, load_dotenv

from core.utils import load_modules

load_dotenv(find_dotenv())

# env and consts
BASE_DIR = dirname(dirname(__file__))
DEBUG = easy_env.get_bool('DEBUG', False)
DATABASE_URL = easy_env.get_str('DATABASE_URL', raise_error=True)

# telegram
TELEGRAM_BOT_TOKEN = easy_env.get_str('TELEGRAM_BOT_TOKEN')

# trakt
TRAKT_CLIENT_ID = easy_env.get_str('TRAKT_CLIENT_ID')
TRAKT_CLIENT_SECRET = easy_env.get_str('TRAKT_CLIENT_SECRET')
TRAKT_REDIRECT_URI = easy_env.get_str('TRAKT_REDIRECT_URI')

# celery
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_WORKER_CONCURRENCY = easy_env.get_int('CELERY_WORKER_CONCURRENCY',
                                             multiprocessing.cpu_count())

# logging
logging.addLevelName(logging.DEBUG, '🐛 ')
示例#5
0
 def test_bad_value(self):
     os.environ['VALUE'] = 'not bool'
     with self.assertRaises(ValueError):
         environ.get_bool('VALUE')
示例#6
0
 def test_raise_error(self):
     with self.assertRaises(KeyError):
         environ.get_bool('VALUE', raise_error=True)
示例#7
0
 def test_none(self):
     value = environ.get_bool('VALUE')
     self.assertIsNone(value)
示例#8
0
 def test_get_default(self):
     value = environ.get_bool('VALUE', True)
     self.assertTrue(value)
     value = environ.get_bool('VALUE', False)
     self.assertFalse(value)