Python
07 Dec 2011
 
 
 
 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
import MySQLdb
import time
import pymongo
mongo = pymongo.Connection()['filesdrop']
db = MySQLdb.connect("localhost",user="web",passwd="web-**",db="dle")
cursor = db.cursor()
cursor.execute('set names utf8')
cursor.execute('truncate dle_post')
cursor.execute('truncate dle_tags')
for upload in mongo.upload.find({}, limit=0):
content = upload['description'].encode('utf-8', 'ignore')
title = upload['title'].encode('utf-8', 'ignore')
tags = upload['tags'].encode('utf-8', 'ignore')
cursor.execute("""
INSERT INTO dle_post
(date, short_story, full_story, title,
category, approve, allow_main, alt_name,
autor, keywords, xfields, tags)
VALUES(NOW(), %s, %s, %s,
%s, %s, %s, %s,
%s, %s, %s, %s)
""", [content, '', title, 1,
1, 1, 'title', 'admin',
'', '', tags])
news_id = cursor.lastrowid
print news_id
for tag in tags.split(','):
tag = tag.strip().encode('utf-8')
cursor.execute("""
INSERT INTO dle_tags
(news_id, tag) VALUES(%s, %s)
""", [news_id, tag])