You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
# -*- coding: utf-8 -*-
|
|
import MySQLdb
|
|
from MySQLdb.cursors import DictCursor
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from functions.translate import fill_with_signal
|
|
from article.models import Article
|
|
from accounts.models import User
|
|
from django.db import IntegrityError
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
db = MySQLdb.connect(host="localhost",
|
|
user="kotzilla",
|
|
passwd="qazedc",
|
|
db="old_expomap",
|
|
charset='utf8',
|
|
cursorclass=DictCursor)
|
|
cursor = db.cursor()
|
|
sql = """SELECT news_id as id ,
|
|
headline as main_title,
|
|
content as description,
|
|
cid as author,
|
|
date_added as created
|
|
|
|
FROM `latest_news` order by created DESC"""
|
|
|
|
cursor.execute(sql)
|
|
|
|
result = cursor.fetchall()
|
|
user = User.objects.get(id=1)
|
|
|
|
Article.objects.news().delete()
|
|
|
|
for a in result:
|
|
if len(a['main_title'])>255 or not a['main_title']:
|
|
continue
|
|
article = Article(type=Article.news,
|
|
id=a['id'],
|
|
created=a['created'])
|
|
if a['author']:
|
|
try:
|
|
author = User.objects.get(id=a['author'])
|
|
except User.DoesNotExist:
|
|
author = user
|
|
else:
|
|
author = user
|
|
|
|
article.author = author
|
|
|
|
article.translate('ru')
|
|
article.main_title = a['main_title']
|
|
article.description = a['description']
|
|
try:
|
|
article.save()
|
|
print(article)
|
|
except :
|
|
print ('error. id:%d'%a['id'])
|
|
|
|
|
|
|
|
#print(a['main_title'])
|
|
|
|
|