Ejemplo n.º 1
0
    def __init__(self):
        DbManager.__init__(self)

        # {'class name': instance}
        self.instances = {}

        # [(class name, function name, args, kwargs, interval_min), ]
        self.functions = []
Ejemplo n.º 2
0
class BaseCharacterModalView(ModalView):
    def start_up(self):
        self.dbManager = DbManager()
        self.commonClasses = CommonClasses()
        self.get_characters()
        self.update_modal_view()

    def create_connection(self):
        self.dbManager.create_connection()

    def close_connection(self):
        self.dbManager.close_connection()
Ejemplo n.º 3
0
    def __init__(self, type):
        self.scraper = WebScraper()
        self.logger = Logger()
        self.db = DbManager.get_instance()

        if type == 'fill_database':
            self.__init_fill_db()
class CollectionModalView(BaseCharacterModalView):
    def start_up(self):
        self.dbManager = DbManager()
        self.commonClasses = CommonClasses()
        self.get_characters()
        self.update_modal_view()

    def get_characters(self):
        self.create_connection()
        self.characterList = []
        characters = self.dbManager.get_character_table()
        if characters:
            for character in characters:
                character = self.convert_to_character_class(character)
                self.characterList.append(
                    {'text': character.name + ', ' + str(character.amount)})
        hide_widget(self.ids.collection_list, False)
        self.close_connection()

    @staticmethod
    def convert_to_character_class(character):
        #Name, Amount, Lewd, Wholesome, Duplicate
        character = CommonClasses.Character(character[0], character[1])
        return character

    def update_modal_view(self):
        self.ids.collection_list.data = self.characterList
        self.ids.collection_list.refresh_from_data()
Ejemplo n.º 5
0
 def __init__(self, **kwargs):
     super(MainPage, self).__init__(**kwargs)
     self.dbManager = DbManager()
     self.characterDbManager = CharacterDbManager()
     self.commonClasses = CommonClasses()
     self.suggestionUpdater = SuggestionUpdater()
     self.default_values = grab_default_values()
     self.mainPageSuggestionsUpdater = MainPageSuggestionsUpdater()
Ejemplo n.º 6
0
 def __init__(self, tile_name, column_name, pairs):
     self.db = DbManager.get_instance()
     self.scraper = WebScraper()
     self.cursor = None
     self.logger = Logger()
     self.column_name = column_name
     self.tile_name = tile_name
     self.pairs = pairs
Ejemplo n.º 7
0
    def __init__(self):
        available_hosts = ['rpi1', 'rpi2']

        self.logger = Logger()
        self.scraper = WebScraper()
        self.db = DbManager.get_instance()
        depts = self.scraper.get_all_departments()
        workers = []

        for tile in depts:
            if good_table_name(tile) in Settings.BANNED_TILES:
                continue
            self.db.create_table(good_table_name(tile))
            for column in depts[tile]:
                if column in Settings.BANNED_COLUMNS:
                    continue

                worker = Worker(good_table_name(tile), column,
                                depts[tile][column])

                proc = multiprocessing.Process(target=worker.start_working)
                self.logger.starting_worker(tile, column)

                workers.append((worker, proc))
                proc.start()
                time.sleep(5)

                while len(workers) >= 4:
                    for w, p in workers:
                        p.join(timeout=0)
                        if not p.is_alive():
                            workers.remove((w, p))
                            break

        def start_ssh_job(self, host, tile):
            timeout = 60 * 60 * 2

            process = subprocess.Popen([
                'ssh', host,
                '"python3 emag-scraping/process.py {}"'.format(tile)
            ])
            time.sleep(5)

            if process.poll() is not None:
                print('Done {}'.format(tile))
Ejemplo n.º 8
0
 def start_up(self):
     self.dbManager = DbManager()
     self.commonClasses = CommonClasses()
     self.get_characters()
     self.update_modal_view()
class CharacterTextInput(TextInput):
    def __init__(self, **kwargs):
        super(CharacterTextInput, self).__init__(**kwargs)

    def keyboard_on_key_down(self, instance, keycode, text, modifiers):
        self.create_database_manager()
        self.create_connection()
        self.suggestions_data = []
        if keycode[1] == 'backspace':
            self.backspace()
        if keycode[1] == 'left':
            self.move_cursor_left(self)
            return
        if keycode[1] == 'right':
            self.move_cursor_right(self)
            return
        if self.check_length(keycode):
            suggestions = self.get_suggestions(keycode)
            self.update_suggestion_data(suggestions)
        elif not self.check_length(keycode):
            self.hide_drop_down()
        else:
            pass
        self.close_connection()

    def create_database_manager(self):
        self.dbManager = DbManager()

    def create_connection(self):
        self.dbManager.create_connection()

    def close_connection(self):
        self.dbManager.close_connection()

    def update_suggestion_data(self, suggestions):
        if len(suggestions) == 0:
            self.hide_drop_down()
        else:
            # change suggestions into proper format for the suggestions_dropdown
            for suggestion in suggestions:
                self.suggestions_data.append({'text': str(suggestion)})
            self.update_suggestions()
            self.suggestions_data.clear()
            self.show_drop_down()

    def update_suggestions(self):
        # update and refresh suggestions_dropdown
        App.get_running_app(
        ).root.ids.suggestions_dropdown.data = self.suggestions_data
        App.get_running_app().root.ids.suggestions_dropdown.refresh_from_data()

    def hide_drop_down(self):
        hide_widget(App.get_running_app().root.ids.suggestions_dropdown)

    def show_drop_down(self):
        hide_widget(App.get_running_app().root.ids.suggestions_dropdown, False)

    def move_cursor_left(self):
        self.do_cursor_movement(action='cursor_left')

    def move_cursor_right(self):
        self.do_cursor_movement(action='cursor_right')

    def check_length(self, keycode):
        if len(self.text) >= 3:
            return True
        elif len(self.text + keycode[1]) >= 3 and keycode[1] != 'backspace':
            return True
        else:
            False

    def backspace(self):
        if self.selection_text != '':
            self.delete_selection()
            # Fixes visual cursor position bug
            CharacterTextInput.move_cursor_left(self)
            CharacterTextInput.move_cursor_right(self)
        else:
            self.do_backspace()

    def get_suggestions(self, keycode):
        if keycode[1] == 'backspace':
            suggestions_from_sql = self.dbManager.search_for_suggestions(
                self.convert_search_text_to_sql(self.text))
        else:
            suggestions_from_sql = self.dbManager.search_for_suggestions(
                self.convert_search_text_to_sql(self.text + keycode[1]))
        suggestions = self.sql_to_list(suggestions_from_sql)
        return suggestions

    def sql_to_list(self, sql_cursor):
        item_list = []
        for item in sql_cursor:
            item_list.append(item[0])
            if len(item_list) >= 10:
                return item_list
        return item_list

    def convert_search_text_to_sql(self, search_text):
        # modify for 'like' command in sqlite
        search_text = '%' + search_text + '%'
        return search_text
 def create_database_manager(self):
     self.dbManager = DbManager()
Ejemplo n.º 11
0
    def __init__(self, bot_config, sleep_time_sec=1):
        # Init TwitterBotBase.
        TwitterBotBase.__init__(self, bot_config, sleep_time_sec)

        # Init DbManager.
        DbManager.__init__(self)
Ejemplo n.º 12
0
 def __init__(self):
     self.dbManager = DbManager()