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
37
38
39
40
41
42
43
44
45
46
47
48
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()
|