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])