~crocmagnon/blog

ref: f6d6d7b850df58a2f5ce8e8555f9b0328462224d blog/migration.py -rw-r--r-- 1.1 KiB
f6d6d7b8Gabriel Augendre Add task to notify commenters once their comment has been moderated. 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sqlite3


def main():
    writefreely = sqlite3.connect("db/writefreely.db")
    db = sqlite3.connect("db/db.sqlite3")
    writefreely_c = writefreely.cursor()
    db_c = db.cursor()
    writefreely_c.execute(
        "SELECT slug, created, updated, view_count, title, content, pinned_position FROM posts;"
    )
    for line in writefreely_c.fetchall():
        ret = db_c.execute(
            "INSERT INTO articles_article(title, content, status, published_at, created_at, updated_at, author_id, views_count, slug) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
            (
                line[4],
                line[5],
                "published",
                line[1],
                line[1],
                line[2],
                1,
                line[3],
                line[0],
            ),
        )
        if line[6] is not None:
            db_c.execute(
                "INSERT INTO articles_page(article_ptr_id, position) VALUES (?, ?);",
                (ret.lastrowid, line[6]),
            )
    db.commit()


if __name__ == "__main__":
    main()