import sys
import logging
import sqlite3
sys.path.insert(0, 'Application')
from scripts.logic.logic import ConnectionDB
from logger.log import MyLogging

super_logger = MyLogging().setup_logger(
    'drop_tables_logger', 'Application/logger/logfile_drop_tables.log')


class DropTableDb:
    """The class for deleting tables."""
    def __init__(self):
        self.connect_db = ConnectionDB().conn

    def drop_channal(self):
        """Request to drop the 'channel' table."""
        try:
            with self.connect_db:
                request = """DROP TABLE IF EXISTS channal"""
                self.connect_db.execute(request)
                self.connect_db.commit()

        except Exception:
            super_logger.error('Error', exc_info=True)

    def drop_groups(self):
        """Request to drop the 'groups' table."""
        try:
            with self.connect_db:
Ejemplo n.º 2
0
import sys
import sqlite3
sys.path.insert(0, 'Application')
from scripts.logic.logic import ConnectionDB
from logger.log import MyLogging

super_logger = MyLogging().setup_logger(
    'preparing_db_logger', 'Application/logger/logfile_preparing.log')


class PreparDb:
    """The class for creating tables in a database."""
    def __init__(self):
        self.connect_db = ConnectionDB().conn

    def foreign_keys_on(self):
        """Allows you to use linked keys."""
        try:
            with self.connect_db:
                request = """PRAGMA foreign_keys=on"""
                self.connect_db.execute(request)
        except Exception:
            super_logger.error('Error', exc_info=True)

    def create_channel(self):
        """This method creates the 'channel' table."""
        try:
            with self.connect_db:
                request = """CREATE TABLE IF NOT EXISTS channel(
                            channel_id INTEGER PRIMARY KEY
                            AUTOINCREMENT NOT NULL,
Ejemplo n.º 3
0
import aiohttp
from aiohttp import web, request

from scripts.logic.logic import Telegram
from scripts.logic.logic import HandlerReqDb
from scripts.logic.logic import HandlerServer
from scripts.logic.logic import send_error_message
from logger.log import MyLogging
from config import TOKEN

app = web.Application()
teleg = Telegram()
hand_req_db = HandlerReqDb()
hand_serv = HandlerServer

super_logger = MyLogging().setup_logger('server_bot',
                                        'Application/logger/logfile.log')


async def receive_update(request):
    try:
        async with aiohttp.ClientSession() as session:
            req = await request.json()
            h_s = hand_serv(req)
            chat_id = h_s.chat_id
            text_message = h_s.text_message
            chec_det_wal = await h_s.chec_det_wal(text_message, chat_id)

            if chec_det_wal:
                text = "Секундочку, Ваши обои уже ждут встречи с Вами \U0001f929"
                await teleg.send_message(chat_id, text)
                pix = await hand_req_db.hand_get_pixresolution(chat_id)
Ejemplo n.º 4
0
import time
import json
import sqlite3
import requests
from scripts.logic.abstract_for_channel import AbstractCannel
from logger.log import MyLogging

super_logger = MyLogging().setup_logger(
    'logic_logger', 'Application/logger/logfile_logic.log')


class ConnectionDB:
    """Class for connect to DB."""
    def __init__(self):
        self.dbname = self.get_config_db()[0]
        self.conn = sqlite3.connect(self.dbname)
        self.cursor = self.conn.cursor()

    def get_config_db(self) -> tuple:
        """The method getting informations of configuration file."""
        with open('Application/config.json') as config:
            json_str = config.read()
            json_str = json.loads(json_str)
        dbname = str(json_str['data_Base']['dbname'])
        vktok = str(json_str['channel']['VK']['token'])
        sched = str(json_str['schedule'])
        return (dbname, vktok, sched)


class RequestsDb:
    """Class for requests DB.
import psycopg2
import time
import json
import os
from logger.log import MyLogging
import logging

super_logger = MyLogging().setup_logger(
    'core_logic', 'Application/logger/logfile.log')  #, logging.INFO)


class ErrorApi(Exception):
    pass


class AuthenticationError(Exception):
    pass


class ConnectError(Exception):
    pass


class Estimation:
    def __init__(self, num_all):
        self.num = num_all[:-1]
        self.cal = num_all[-1]
        if self.cal == 'd':
            self.num = int(self.num) * 8
        if self.cal == 'w':
            self.num = int(self.num) * 40