Пример #1
0
    def __init__(self, bot_config):
        self.bot_config = bot_config

        setup_logging(loglevel="INFO", console_loglevel="DEBUG",
                      log_path_format="logs/botlogs/%Y/%m/%Y-%m-%d.log")

        self.log = logging.getLogger("bot")

        conninfo = self.bot_config["Connection Info"]
        self.networking = Networking(conninfo["host"], conninfo["port"],
                                     timeout=conninfo["timeout"],
                                     floodcontrol_mode="msg_count",

                                     floodcontrol_config={"burst_count_per_10_seconds": 5,
                                                          "base_delay": 0.5,
                                                          "max_delay": 2})

        msginfo = self.bot_config["Bot Options"]["Message Sending"]
        self.networking.set_wait_coefficient(base_delay=msginfo["minimum delay"],
                                             messages_per_minute=msginfo["messages per minute"],
                                             burst=msginfo["burst"])

        self.message_handler = MessageHandler()

        self.user_messages = UserMessages(self)
        self.server_info = ServerInformation(self)
        self.channel_manager = ChannelManager(self)

        self.tools = Tools()

        self.log.info("All modules configured and set up. Bot is ready to go.")

        self._shutdown = False
Пример #2
0
def start():
    setup_logging('sanic.root', replace=True)
    setup_logging('sanic.error', replace=True)
    app.run(host='0.0.0.0',
            workers=SERVER_WORKERS_COUNT,
            port=SERVER_PORT,
            debug=DEBUG,
            ssl={
                'cert': SSL_CERT,
                'key': SSL_KEY
            })
Пример #3
0
def start():


    app = Sanic(configure_logging=False)
    app.request_middleware.append(redirect_to_ssl)

    app.config.REQUEST_MAX_SIZE = 4000
    app.config.REQUEST_TIMEOUT = 5
    app.config.RESPONSE_TIMEOUT = 5

    config.LOG_TELEGRAM_APP_NAME = 'proxy'

    setup_logging('sanic.root', replace=True)
    setup_logging('sanic.error', replace=True)

    app.run(host='0.0.0.0', workers=1, port=80, debug=False, access_log=False)
Пример #4
0
def setup_env():
    """Sets up environment for training or testing."""
    if dist.is_master_proc():
        # Ensure that the output dir exists
        os.makedirs(cfg.OUT_DIR, exist_ok=True)
        # Save the config
        config.dump_cfg()
    # Setup logging
    logging.setup_logging()
    # Log the config as both human readable and as a json
    logger.info("Config:\n{}".format(cfg))
    logger.info(logging.dump_log_data(cfg, "cfg"))
    # Fix the RNG seeds (see RNG comment in core/config.py for discussion)
    np.random.seed(cfg.RNG_SEED)
    torch.manual_seed(cfg.RNG_SEED)
    # Configure the CUDNN backend
    torch.backends.cudnn.benchmark = cfg.CUDNN.BENCHMARK
Пример #5
0
from typing import Any

from flask import Flask

import config
from core.database import db_session
from views.content import content_bp
from views.login import login_bp
from core.logging import setup_logging


setup_logging()
app = Flask(__name__, template_folder='templates')
app.secret_key = config.SECRET_KEY
app.register_blueprint(login_bp, url_prefix="/login")
app.register_blueprint(content_bp, url_prefix="/content")


@app.teardown_appcontext
def shutdown_session(exception: Any = None) -> None:
    db_session.remove()


if __name__ == "__main__":
    # Just to simplify debugging
    app.run("0.0.0.0", 5000, debug=True)
Пример #6
0
import asyncio
from datetime import datetime

from apps.mileapi.constants import TransferAssetsTransaction
from core.di import db
from core.logging import setup_logging

logger = setup_logging('indexer_stat')


async def calc_statistics():
    while True:
        await asyncio.sleep(60 * 1)
        start = datetime.now()

        await db.status("delete from stat_day where date < '2018-01-01'")
        await db.status("delete from stat_month where date < '2018-01-01'")

        await calc_turnover()
        await calc__tx__nonempty_blocks__count()
        await calc_blocks_count()
        await calc_bp_income()
        await calc_xdr_count()

        time = (datetime.now() - start).total_seconds()
        logger.info(f"Stat calc finished: {time} seconds")


async def calc_turnover():
    try:
        await db.status(
Пример #7
0
from dateutil.parser import parse
from sqlalchemy.engine.url import URL

from apps.explorer.indexer_stat.stat import calc_statistics
from apps.explorer.models import Block, Wallet, Transaction
from apps.mileapi.api import get_current_block, get_block, get_wallet, get_wallet_after_block
from apps.mileapi.constants import TX_TYPES, TransferAssetsTransaction, RegisterNodeTransactionWithAmount
from core.collections import unique_deque
from core.config import DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, INDEXER_DB_POOL_MIN_SIZE, INDEXER_DB_POOL_MAX_SIZE, \
    INDEXER_TASKS_LIMIT, \
    GENESIS_BLOCK
from core.di import db
from core.logging import setup_logging

logger = setup_logging('indexer')

last_processed_block_id = 0

TASK_BLOCK = 0
TASK_WALLET = 1
TASKS_NAMES = {TASK_BLOCK: 'block', TASK_WALLET: 'wallet'}


def start(stage=2):
    """stage1 - cold start first-time db fill, stage2 - after db filled"""
    assert stage in (1, 2)

    logger.error('started')

    global last_processed_block_id
Пример #8
0
import asyncio
import time
from typing import List
import logging
from uuid import uuid4

import motor.motor_asyncio
from pymongo.errors import PyMongoError

# сетап конфиг и логгер
from core.logging import setup_logging

setup_logging(default_level=logging.DEBUG)
logger = logging.getLogger(__name__)


class MongodbService:
    """
    Class for async CRUD document in Mongo
    """
    def __init__(self,
                 host: str = 'localhost',
                 port: int = 27017,
                 db: str = 'test_database',
                 collection: str = 'test_collection'):
        self._client = motor.motor_asyncio.AsyncIOMotorClient(host, port)
        self._db = self._client[db]
        self._collection = self._db[collection]

    async def create_one(self, dto) -> str:
        """
Пример #9
0
from datetime import datetime
from decimal import Decimal

import pytz
from sanic import response
from sanic.exceptions import NotFound
from sanic.request import Request
from sanic.response import redirect

from apps.explorer.models import Transaction, Block, Wallet, MonthStat, DayStat
from core.di import app, jinja
from core.logging import setup_logging
from core.pagination import get_paginator
from core.utils import url_without_qs_param

logger = setup_logging('explorer.controllers')

#################################################################################


@app.exception(NotFound)
@jinja.template('error404.html')
async def error_page(request, exception):
    return {}


@app.exception(Exception)
@jinja.template('error.html')
async def error_page(request, exception):
    try:
        logger.error(str(exception))