From 40cc4103698cbce670bb40f63670f7de44a5a497 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 16 Aug 2020 20:24:08 +0200 Subject: [PATCH] Add migration script --- README.md | 1 + migration.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 migration.py diff --git a/README.md b/README.md index 7a549d0..e92c91f 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,4 @@ Simple blog management system. 2. Add pagination links 4. Find a nice way to display metadata (author, dates, etc) 5. Allow adding pages (pinned articles ?) +6. Add syntax coloration to code blocks diff --git a/migration.py b/migration.py new file mode 100644 index 0000000..23a78ae --- /dev/null +++ b/migration.py @@ -0,0 +1,31 @@ +import sqlite3 + + +def main(): + writefreely = sqlite3.connect("writefreely.db") + db = sqlite3.connect("db.sqlite3") + writefreely_c = writefreely.cursor() + db_c = db.cursor() + writefreely_c.execute( + "SELECT slug, created, updated, view_count, title, content FROM posts;" + ) + for line in writefreely_c.fetchall(): + 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], + ), + ) + db.commit() + + +if __name__ == "__main__": + main()