示例#1
0
 def enddate(self) -> Optional[datetime.date]:
     """End date of anime."""
     text = self.root.find("enddate").text
     try:
         return parse_date(text)
     except ValueError:
         return None
示例#2
0
def migrate2(database):
    with database:
        cur = database.cursor()

        # Alter anime.
        cur.execute("""
        CREATE TABLE anime_new (
            aid INTEGER,
            title TEXT NOT NULL UNIQUE,
            type TEXT NOT NULL,
            episodecount INTEGER NOT NULL,
            startdate INTEGER,
            enddate INTEGER,
            PRIMARY KEY (aid)
        )""")
        cur.execute("""
        INSERT INTO anime_new (aid, title, type, episodecount)
        SELECT aid, title, type, episodes
        FROM anime
        """)
        # This is done in Python instead of SQL because f**k timezones.
        row = database.cursor()
        row = row.execute('SELECT aid, startdate, enddate FROM anime')
        cur.executemany(
            """UPDATE anime_new
            SET startdate=?, enddate=?
            WHERE aid=?""",
            ([timestamp(parse_date(startdate)) if startdate else None,
              timestamp(parse_date(enddate)) if enddate else None,
              aid]
             for aid, startdate, enddate in row),
        )
        cur.execute('DROP TABLE anime')
        cur.execute('ALTER TABLE anime_new RENAME TO anime')

        # Add title index.
        cur.execute("""
        CREATE INDEX anime_titles ON anime (title)
        """)

        # Add file_priority.
        cur.execute("""
        CREATE TABLE file_priority (
            id INTEGER PRIMARY KEY,
            regexp TEXT NOT NULL,
            priority INTEGER NOT NULL
        )""")