def __init__( self , configFile , visible = True ) :
		self.configFile = configFile
		self.config = Config( self.configFile )
		self.config.fetch( )

		self.visible = visible
		self.password = None

		self.__prepareConfig( )

		self.controller = Controller( self )
		self.controller.configure( )
Example #2
0
    def __init__(self, entries: Set[ControlSequence]):
        """
		BinaryTable Constructor.

		:param entries: Set[ControlSequence], The list of
			control sequences making up the table.

		"""

        Controller.__init__(self)
        entries = {} if entries is None else entries
        self.__entries = set()

        for entry in entries:
            self.add(entry=entry)
Example #3
0
    def __init__(self, entries: Set[Edge]):
        """
		Table Constructor.

		:param entries: Set[Edge], The set of mappings
			composing the finite state machine's graph.

		"""

        Controller.__init__(self)
        entries = {} if entries is None else entries
        self.__entries = set()

        for entry in entries:
            self.add(edge=entry)
class Application( Interface ) :
	def __init__( self , configFile , visible = True ) :
		self.configFile = configFile
		self.config = Config( self.configFile )
		self.config.fetch( )

		self.visible = visible
		self.password = None

		self.__prepareConfig( )

		self.controller = Controller( self )
		self.controller.configure( )

	def getDBA( self , path , query = None ) :
		conn = SQLite( creator = self , filename = query )
		conn.prepare( path )

		return conn

	def prepareSQLite3( self ) :
		self.conn = self.getDBA( self.config[ "db" ][ "path" ] , self.config[ "db" ][ "query" ] )

		for entity in self.conn.config[ "handler" ] :
			consumer = SQLiteConsumer( entity = entity , creator = self.conn )
			setattr( self , entity , consumer )

		return self

	def __prepareConfig( self ) :
		self.config[ "libPath" ] = self.preparePath( self.config[ "libPath" ] )
		self.config[ "driverPath" ] = self.preparePath( self.config[ "driverPath" ] )

		for key in self.config[ "gui" ][ "icon" ] :
			self.config[ "gui" ][ "icon" ][ key ] = self.preparePath( self.config[ "gui" ][ "icon" ][ key ] )

		for key in ( "query" , "path" , "recrypt" ) :
			self.config[ "db" ][ key ] = self.preparePath( self.config[ "db" ][ key ] )

		self.config[ "gui" ][ "widgetPath" ] = self.preparePath( self.config[ "gui" ][ "widgetPath" ] )

		return self

	def preparePath( self , path , add = '..' ) :
		args = [ os.path.dirname( __file__ ) ]

		if add is not None :
			args.append( add )

		args.append( path )
		result = os.path.abspath( os.path.join( * args ) )

		return result

	def prepare( self ) :
		self.ui = UI( None , config = self.config , creator = self , visible = self.visible )

		self.password = Password( self.ui )
		self.password.prepare( )

		result = self.password.login( )
		if not result :
			self.exception( "invalid_password" )

		self.prepareSQLite3( )
		self.ui.prepare( )

		return self

	def execute( self ) :
		if self.visible :
			self.ui.execute( )

		return self

	def action( self , action , * argv , ** kwargs ) :
		error = self.config[ "error" ]
		def onError( exception ) :
			self.ui.message(
				title	= str( exception ) ,
				message	= error[ "%s_comment" % action ].format( * argv ) ,
			)
			raise exception
		try :
			target = lambda : self.controller.action( action , onError , argv , kwargs )
			finish = lambda : self.ui.update( ) and self.ui.message(
				title	= error[ "%s_title" % action ].format( * argv , ** kwargs ) ,
				message	= error[ "%s_comment" % action ].format( * argv , ** kwargs ) ,
			)
			self.run( target = target , finish = finish )
		except Exception as exception :
			onError( exception )

			return False
		return True

	def run( self , target , finish ) :
		if not self.visible :
			target( )

			return finish( )

		onFinish = lambda: self.ui.update( ) and finish( )

		if not self.thread( target = target , finish = onFinish ) :
			self.exception( "unknown" )

		return False
Example #5
0
# /usr/bin/env python3.7
# -*- coding: utf-8 -*-

import vk
import peewee
from random import randint
from requests import post
from config import VK_API_ACCESS_TOKEN, VK_API_VERSION, GROUP_ID
from lib.DataBase import DataBase, IntegrityError, OperationalError
from lib.Controller import Controller
from models.Chat import find_chat

api = vk.API(vk.Session(access_token=VK_API_ACCESS_TOKEN), v=VK_API_VERSION)
controller = Controller()
db = DataBase()
longPoll = api.groups.getLongPollServer(group_id=GROUP_ID)
server, key, ts = longPoll['server'], longPoll['key'], longPoll['ts']

while True:
    try:
        try:
            db.open_connection()
        except (peewee.OperationalError):
            print("connection")
    except (IntegrityError, OperationalError):
        db = DataBase()
        db.open_connection()

    print("new LongPoll post request")
    longPoll = post('%s' % server, data={'act': 'a_check',
                                         'key': key,
Example #6
0
    except (IntegrityError, OperationalError):
        db = DataBase()
        db.open_connection()

    print("new LongPoll post request")
    longPoll = post('%s' % server,
                    data={
                        'act': 'a_check',
                        'key': key,
                        'ts': ts,
                        'wait': 25
                    }).json()

    if longPoll.get('updates') and len(longPoll['updates']) != 0:
        for update in longPoll['updates']:
            controller = Controller(update['object'])

            if update['object'].get('action'):
                controller.action_parser(update['object']['action'])
            else:
                controller.update_user_stats()
                controller.add_text()
                controller.stop_lines()
                controller.get_reaction()
                # дальше реальный Коммандхендлер
                controller.is_mini_request_for_reply()
                if controller.is_request_bot():
                    controller.parse_command()
                controller.duel()
            del controller
    db.close_connection()
Example #7
0
        except (peewee.OperationalError):
            print("connection")
    except (IntegrityError, OperationalError):
        db = DataBase()
        db.open_connection()
    print("new LongPoll post request")
    longPoll = post('%s' % server,
                    data={
                        'act': 'a_check',
                        'key': key,
                        'ts': ts,
                        'wait': 25
                    }).json()
    if longPoll.get('updates') and len(longPoll['updates']) != 0:
        for update in longPoll['updates']:
            print(update)
            controller = Controller(update['object'])
            if update['object'].get('action'):
                print(update['object']['action'])
                # controller.action_parser(update['object']['action'])
            else:
                controller.payloadParse()
                print(update['object'])
            del controller
    db.close_connection()
    if longPoll.get('failed'):
        longPoll = api.groups.getLongPollServer(group_id=GROUP_ID)
        server, key, ts = longPoll['server'], longPoll['key'], longPoll['ts']
    ts = longPoll['ts']
    print(ts)