Esempio n. 1
0
 def __set_last_key_migration(self) -> None:
     cursor = Db().connect().cursor(dictionary=True)
     cursor.execute(
         "SELECT `data` FROM `settings` WHERE `id` = 'migrations'")
     result = cursor.fetchall()
     if result:
         self.__last_key_migration = int(result[0]['data'])
     else:
         cursor.execute(
             "INSERT INTO `settings` (`id`, `data`) VALUES ('migrations', '0')"
         )
         Db().connect().commit()
     cursor.close()
Esempio n. 2
0
def get_sites(one_row: bool = False) -> dict:
    cursor = Db().connect().cursor(dictionary=True)
    cursor.execute(
        'SELECT * FROM `parser_site` WHERE `parse` = 0 and `process` = 0 ')
    if one_row:
        result = cursor.fetchone()
    else:
        result = cursor.fetchall()
    cursor.close()
    return result
Esempio n. 3
0
def save_count_links(id: int, count_links: int, count_tmp_links: int) -> None:
    cursor = Db().connect().cursor()
    cursor.execute(
        'UPDATE `parser_site` SET `links` = %s,`tmp_links` = %s WHERE `id` = %s',
        [count_links, count_tmp_links, id])
    Db().connect().commit()
    cursor.close()
Esempio n. 4
0
def set_result_parse(id: int, count_links: int) -> None:
    cursor = Db().connect().cursor()
    cursor.execute(
        'UPDATE `parser_site` SET `parse` = 1,`process` = 0,`end` = NOW(),`links` = %s WHERE `id` = %s',
        [count_links, id])
    Db().connect().commit()
    cursor.close()
Esempio n. 5
0
 def __update_last_key_migration(self, key: int) -> None:
     cursor = Db().connect().cursor()
     cursor.execute(
         "UPDATE `settings` SET `data` = %s WHERE `id` = 'migrations'",
         [key + 1])
     Db().connect().commit()
     cursor.close()
Esempio n. 6
0
 def __create_settings_table(self) -> None:
     cursor = Db().connect().cursor()
     cursor.execute(
         "CREATE TABLE IF NOT EXISTS `settings` ( `id`  VARCHAR(255) NOT NULL , `data` TEXT NULL DEFAULT NULL , UNIQUE (`id`)) ENGINE = InnoDB;"
     )
     Db().connect().commit()
     cursor.close()
Esempio n. 7
0
def create_log(link: str, table: str, special_links: str = None) -> int:
    cursor = Db().connect().cursor()
    cursor.execute(
        "INSERT INTO `parser_site` (`id`, `site`, `tb`, `special_link`, `parse`, `process`, `links`, `tmp_links`, `start`, `end`) VALUES (NULL, %s,%s, %s, '0', '1', '0', '0',  NOW(), NULL)",
        [link, table, special_links])
    Db().connect().commit()
    id = cursor.lastrowid
    cursor.close()
    return id
Esempio n. 8
0
    def run(self) -> None:
        if self.__sql_migration:
            if self.__sql_migration:
                cursor = Db().connect().cursor()
                last_key = 0
                for key, migration in enumerate(self.__sql_migration):
                    if key >= self.__last_key_migration:
                        cursor.execute(migration)
                        last_key = key

                Db().connect().commit()
                cursor.close()
                if last_key + 1 > self.__last_key_migration:
                    self.__update_last_key_migration(last_key)
Esempio n. 9
0
def set_process(id: int) -> None:
    cursor = Db().connect().cursor()
    cursor.execute(
        'UPDATE `parser_site` SET `process` = 1,`start` =  NOW() WHERE `id` = %s',
        [id])
    Db().connect().commit()