Пример #1
0
    def save(self):
        """
        Save the chapter in the database
        """
        new_chapters = 0
        database = Database()
        check_query = """SELECT id, all_pages FROM chapter WHERE manga_id=%s AND number=%s"""
        insert_query = """INSERT INTO chapter VALUES (NULL, %s, %s, 0, %s)"""
        update_query = """UPDATE chapter SET all_pages=1 WHERE id=%s"""
        for url in self.urls:
            chapter_id = None
            chapter_number = url.split("/")[-1]
            result = database.execute(check_query,
                                      [self.manga_id, chapter_number])

            if result is ():
                database.execute(insert_query,
                                 [chapter_number, url, self.manga_id])
                chapter_id = database.last_inserted_id()
                new_chapters += 1

            else:
                chapter_id = result[0][0]
                self.all_pages = True if result[0][1] == 1 else False

            if not self.all_pages:
                chapter_pages = Pages(self.manga_id, chapter_id, url)
                chapter_pages.save()
                database.execute(update_query, [chapter_id])

        self.log.info("Found %s new chapter(s)" % new_chapters)
Пример #2
0
 def save(self):
     """
     Save the manga in the database
     """
     database = Database()
     query = """INSERT INTO manga VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s)"""
     database.execute(query, [
         self.muID, self.url, None, self.title, self.description,
         self.status, 0, None
     ])
     self.id = database.last_inserted_id()
Пример #3
0
    def save(self):
        """
        Checks for existing genders on the database,
        then links the gender to the manga
        """
        gender_id = None
        database = Database()
        check_query = """SELECT id FROM gender_tags WHERE tag_name=%s"""
        insert_query = """INSERT INTO gender_tags VALUES (NULL, %s)"""
        foreign_query = """INSERT INTO manga_gender_tags VALUES (%s, %s)"""
        for gender in self.genders:
            result = database.execute(check_query, [gender])
            if result is ():
                database.execute(insert_query, [gender])
                gender_id = database.last_inserted_id()

            else:
                gender_id = result[0][0]

            database.execute(foreign_query, [gender_id, self.manga_id])