aboutsummaryrefslogtreecommitdiffstats
path: root/import.py
diff options
context:
space:
mode:
Diffstat (limited to 'import.py')
-rw-r--r--import.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/import.py b/import.py
new file mode 100644
index 0000000..976dce4
--- /dev/null
+++ b/import.py
@@ -0,0 +1,49 @@
+import sqlite3
+import sys
+
+def convert_date(date):
+ return "T".join(date.split(" "))
+
+def import_users(old_conn, new_conn):
+ for row in old_conn.execute("select * from users"):
+ address = old_conn.execute("select * from adress where id=?", (row["adress_id"],)).fetchone()
+ new_conn.execute("insert into users (id, user_name, password, birthday, "
+ "nameday, notify, email, phone, address_line1, address_line2, "
+ "address_city_line) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ (row["id"], row["name"], row["password"],
+ "/".join((str(row["birthday"]), str(row["birthmonth"]))),
+ "/".join((str(row["feastday"]), str(row["feastmonth"]))),
+ row["notify"], row["email"], row["cellphone"],
+ address["line1"], address["line2"], " ".join((address["zip"],
+ address["city"]))))
+ new_conn.commit()
+
+def import_news(old_conn, new_conn):
+ for row in old_conn.execute("select * from news"):
+ new_conn.execute("insert into news (id, title, date, content, content_cache, "
+ "user_id) VALUES(?, ?, ?, ?, ?, ?)",
+ (row["id"], row["title"], convert_date(row["date"]),
+ row["raw"], row["news"], row["auteur_id"]))
+ new_conn.commit()
+
+def import_comments(old_conn, new_conn):
+ for row in old_conn.execute("select * from news_comments"):
+ new_conn.execute("insert into comments (id, date, content_cache, user_id, news_id) "
+ "values (?, ?, ?, ?, ?)",
+ (row["id"], convert_date(row["date"]), row["comment"],
+ row["auteur_id"], row["news_id"]))
+ new_conn.commit()
+
+if __name__ == "__main__":
+ old = sys.argv[1]
+ new = sys.argv[2]
+ old_conn = sqlite3.connect(old)
+ old_conn.row_factory = sqlite3.Row
+ new_conn = sqlite3.connect(new)
+ new_conn.row_factory = sqlite3.Row
+ import_users(old_conn, new_conn)
+ import_news(old_conn, new_conn)
+ import_comments(old_conn, new_conn)
+ old_conn.close()
+ new_conn.close()
+