parent
bed7a1ca71
commit
b8469deb09
16 changed files with 119 additions and 494 deletions
@ -1 +0,0 @@ |
|||||||
__author__ = 'root' |
|
||||||
@ -1 +0,0 @@ |
|||||||
__author__ = 'root' |
|
||||||
@ -1,62 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
import xlrd |
|
||||||
from django.core.management.base import BaseCommand |
|
||||||
from django.conf import settings |
|
||||||
from article.models import Article |
|
||||||
from import_xls.excel_settings import article_sett |
|
||||||
from django.db import IntegrityError |
|
||||||
|
|
||||||
|
|
||||||
NEWS_FILE = settings.MEDIA_ROOT+'/import/news.xls' |
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand): |
|
||||||
def handle(self, *args, **options): |
|
||||||
|
|
||||||
f = open(NEWS_FILE, 'r') |
|
||||||
book = xlrd.open_workbook(file_contents=f.read()) |
|
||||||
sheet = book.sheet_by_index(0) |
|
||||||
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
|
||||||
labels = [label for label in row_list[0]] |
|
||||||
existing = 0 |
|
||||||
for row_number, row in enumerate(row_list[2:]): |
|
||||||
|
|
||||||
published = row[4] |
|
||||||
if row[0] != '': |
|
||||||
# in first column ids |
|
||||||
try: |
|
||||||
object = Article.objects.language('ru').get(id=int(row[0])) |
|
||||||
object.type = Article.news |
|
||||||
object.save() |
|
||||||
print(object.type) |
|
||||||
continue |
|
||||||
except ValueError: |
|
||||||
|
|
||||||
object = Article(type=Article.news) |
|
||||||
object.translate('ru') |
|
||||||
except Article.DoesNotExist: |
|
||||||
object = Article(id= int(row[0])) |
|
||||||
object.translate('ru') |
|
||||||
existing += 1 |
|
||||||
else: |
|
||||||
# if id blank - its a new place |
|
||||||
object = Article(type=Article.news) |
|
||||||
object.translate('ru') |
|
||||||
|
|
||||||
for col_number, cell in enumerate(row): |
|
||||||
|
|
||||||
label = labels[col_number] |
|
||||||
setting = article_sett.get(label) |
|
||||||
if setting is None: |
|
||||||
continue |
|
||||||
|
|
||||||
field_name = setting['field'] |
|
||||||
func = setting.get('func') |
|
||||||
value = func(cell) |
|
||||||
setattr(object, field_name, value) |
|
||||||
object.publish_date = published |
|
||||||
try: |
|
||||||
object.save() |
|
||||||
except Exception, e: |
|
||||||
print(e) |
|
||||||
|
|
||||||
@ -1,77 +0,0 @@ |
|||||||
# -*- 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 theme.models import Theme,Tag |
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand): |
|
||||||
def handle(self, *args, **options): |
|
||||||
db = MySQLdb.connect(host="localhost", |
|
||||||
user="debian-sys-maint", |
|
||||||
passwd="LPoEhMvzURQoH1aJ", |
|
||||||
db="expomap_old_blog", |
|
||||||
charset='utf8', |
|
||||||
cursorclass=DictCursor) |
|
||||||
|
|
||||||
cursor = db.cursor() |
|
||||||
|
|
||||||
sql = """SELECT post.post_date as publish_date, |
|
||||||
post.post_content as description, |
|
||||||
post.post_modified as modified, |
|
||||||
post.post_title as main_title, |
|
||||||
post.post_name as slug, |
|
||||||
tag.name as tag_name |
|
||||||
FROM wp_posts post |
|
||||||
INNER JOIN wp_term_relationships rel ON rel.object_id = post.ID |
|
||||||
INNER JOIN wp_terms tag ON tag.term_id=rel.term_taxonomy_id |
|
||||||
WHERE post_status = "publish";""" |
|
||||||
|
|
||||||
cursor.execute(sql) |
|
||||||
result = cursor.fetchall() |
|
||||||
user = User.objects.get(id=1) |
|
||||||
|
|
||||||
tags = {x.name: x.id for x in Tag.objects.language('ru')} |
|
||||||
|
|
||||||
clear_result = {} |
|
||||||
|
|
||||||
errors = [] |
|
||||||
for a in result: |
|
||||||
if a.get('tag_name') in tags.keys(): |
|
||||||
tag_id = tags[a['tag_name']] |
|
||||||
a['tag_id'] = [tag_id] |
|
||||||
print a |
|
||||||
else: |
|
||||||
tag_id = None |
|
||||||
|
|
||||||
if not clear_result.get(a['main_title']): |
|
||||||
clear_result[a['main_title']] = a |
|
||||||
else: |
|
||||||
if clear_result[a['main_title']].get('paid_id') and tag_id: |
|
||||||
clear_result[a['main_title']]['tag_id'].append(tag_id) |
|
||||||
|
|
||||||
|
|
||||||
for a in clear_result.values(): |
|
||||||
article = Article(type=1, |
|
||||||
created = a['publish_date'], |
|
||||||
publish_date= a['publish_date'], |
|
||||||
modified = a['modified'], |
|
||||||
) |
|
||||||
article.author = user |
|
||||||
article.translate('ru') |
|
||||||
article.main_title = a['main_title'] |
|
||||||
article.description = a['description'] |
|
||||||
article.slug = a['slug'] |
|
||||||
if a.get('tag_id'): |
|
||||||
article.tag = [Tag.objects.language('ru').get(id=id) for id in a['tag_id']] |
|
||||||
try: |
|
||||||
article.save() |
|
||||||
except Exception as e: |
|
||||||
errors.append(e) |
|
||||||
|
|
||||||
print errors |
|
||||||
|
|
||||||
|
|
||||||
@ -1,63 +0,0 @@ |
|||||||
# -*- 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 |
|
||||||
|
|
||||||
|
|
||||||
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 articles_description.articles_id as id , |
|
||||||
articles_description.articles_name as main_title, |
|
||||||
articles_description.articles_description as description, |
|
||||||
articles.authors_id as author, |
|
||||||
articles_description.articles_intro as preview, |
|
||||||
articles.articles_date_added as created, |
|
||||||
articles.articles_last_modified as modified, |
|
||||||
articles.articles_date_available as publish_date, |
|
||||||
articles_description.articles_head_title_tag as title, |
|
||||||
articles_description.articles_head_desc_tag as descriptions, |
|
||||||
articles_description.articles_head_keywords_tag as keywords |
|
||||||
|
|
||||||
FROM `articles_description` |
|
||||||
JOIN articles |
|
||||||
ON articles_description.articles_id=articles.articles_id""" |
|
||||||
|
|
||||||
cursor.execute(sql) |
|
||||||
|
|
||||||
result = cursor.fetchall() |
|
||||||
user = User.objects.get(id=1) |
|
||||||
Article.objects.blogs().delete() |
|
||||||
for a in result: |
|
||||||
article = Article(type=Article.blog, |
|
||||||
id=a['id'], |
|
||||||
created=a['created'], |
|
||||||
modified=a['modified'], |
|
||||||
publish_date=a['publish_date']) |
|
||||||
|
|
||||||
article.author = user |
|
||||||
|
|
||||||
article.translate('ru') |
|
||||||
article.main_title = a['main_title'] |
|
||||||
article.preview = a['preview'] |
|
||||||
article.description = a['description'] |
|
||||||
article.title = a['title'] |
|
||||||
article.keywords = a['keywords'] |
|
||||||
if len(a['descriptions'])<255: |
|
||||||
article.descriptions = a['descriptions'] |
|
||||||
article.save() |
|
||||||
print(article) |
|
||||||
|
|
||||||
#print(a['main_title']) |
|
||||||
|
|
||||||
|
|
||||||
@ -1,77 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
import datetime |
|
||||||
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="expomap", |
|
||||||
passwd="7FbLtAGjse", |
|
||||||
db="old_db", |
|
||||||
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 `payed_news` |
|
||||||
WHERE status = 1 |
|
||||||
order by created DESC""" |
|
||||||
|
|
||||||
cursor.execute(sql) |
|
||||||
|
|
||||||
result = cursor.fetchall() |
|
||||||
user = User.objects.get(id=1) |
|
||||||
now = datetime.datetime.now() |
|
||||||
#Article.objects.news().delete() |
|
||||||
|
|
||||||
for a in result: |
|
||||||
title = a['main_title'] |
|
||||||
id = a['id'] |
|
||||||
published = a['created'] |
|
||||||
#try: |
|
||||||
# news = Article.objects.get(id=id) |
|
||||||
#except Article.DoesNotExist: |
|
||||||
# continue |
|
||||||
|
|
||||||
#news.publish_date = published |
|
||||||
#news.save() |
|
||||||
|
|
||||||
if len(a['main_title'])>255 or not a['main_title']: |
|
||||||
continue |
|
||||||
|
|
||||||
|
|
||||||
article = Article(type=Article.news, |
|
||||||
old_id=a['id'], |
|
||||||
publish_date=a['created'], |
|
||||||
created=now) |
|
||||||
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']) |
|
||||||
|
|
||||||
@ -1,45 +0,0 @@ |
|||||||
# -*- 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 |
|
||||||
import xlwt |
|
||||||
from django.utils import translation |
|
||||||
from django.conf import settings |
|
||||||
|
|
||||||
class Command(BaseCommand): |
|
||||||
def handle(self, *args, **options): |
|
||||||
translation.activate('en') |
|
||||||
|
|
||||||
workbook = xlwt.Workbook(encoding = 'utf8') |
|
||||||
worksheet = workbook.add_sheet('My Worksheet') |
|
||||||
|
|
||||||
font = xlwt.Font() |
|
||||||
font.name = 'Times New Roman' |
|
||||||
font.bold = True |
|
||||||
|
|
||||||
style = xlwt.XFStyle() |
|
||||||
# Create the Style |
|
||||||
style.font = font |
|
||||||
|
|
||||||
qs = Article.objects.news() |
|
||||||
worksheet.write(0, 0, 'id') |
|
||||||
worksheet.write(0, 1, 'url') |
|
||||||
worksheet.write(0, 2, 'title') |
|
||||||
|
|
||||||
row = 1 |
|
||||||
for a in qs: |
|
||||||
print a.id |
|
||||||
url = a.slug |
|
||||||
id = a.id |
|
||||||
name = a.main_title |
|
||||||
|
|
||||||
worksheet.write(row, 0, id) |
|
||||||
worksheet.write(row, 1, url) |
|
||||||
worksheet.write(row, 2, name) |
|
||||||
|
|
||||||
row += 1 |
|
||||||
workbook.save(settings.MEDIA_ROOT+'/import/exported_news.xls') |
|
||||||
@ -1,69 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
import MySQLdb |
|
||||||
import datetime |
|
||||||
from django.utils.translation import activate |
|
||||||
from MySQLdb.cursors import DictCursor |
|
||||||
from django.core.management.base import BaseCommand, CommandError |
|
||||||
from django.conf import settings |
|
||||||
import xlrd |
|
||||||
from import_xls.utils import to_theme, to_tag |
|
||||||
from functions.translate import fill_with_signal |
|
||||||
from article.models import Article |
|
||||||
from accounts.models import User |
|
||||||
from django.db import IntegrityError |
|
||||||
from exposition.models import Exposition |
|
||||||
|
|
||||||
NEWS_FILE = settings.MEDIA_ROOT+'/import/exported_news.xls' |
|
||||||
BLOGS_FILE = settings.MEDIA_ROOT+'/import/blogs.xls' |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand): |
|
||||||
def handle(self, *args, **options): |
|
||||||
activate('ru') |
|
||||||
f = open(BLOGS_FILE, 'r') |
|
||||||
book = xlrd.open_workbook(file_contents=f.read()) |
|
||||||
sheet = book.sheet_by_index(0) |
|
||||||
row_list = [sheet.row_values(row_number) for row_number in range(sheet.nrows)] |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print(len(row_list)) |
|
||||||
|
|
||||||
|
|
||||||
existing = 0 |
|
||||||
|
|
||||||
|
|
||||||
for row_number, row in enumerate(row_list[2:]): |
|
||||||
|
|
||||||
id = int(row[0]) |
|
||||||
if id == 49: |
|
||||||
continue |
|
||||||
|
|
||||||
main_title = row[1] |
|
||||||
theme = row[2] |
|
||||||
tag = row[3] |
|
||||||
description = row[4] |
|
||||||
article = Article.objects.language('ru').get(id=id) |
|
||||||
#article.main_title = main_title |
|
||||||
#article.description = description |
|
||||||
#article.save() |
|
||||||
|
|
||||||
|
|
||||||
to_theme(article, theme) |
|
||||||
to_tag(article, tag) |
|
||||||
print(id) |
|
||||||
""" |
|
||||||
try: |
|
||||||
expo = Exposition.objects.filter(translations__name=event)[0] |
|
||||||
except IndexError: |
|
||||||
expo = None |
|
||||||
|
|
||||||
if expo: |
|
||||||
article.exposition = expo |
|
||||||
article.save() |
|
||||||
print(id) |
|
||||||
""" |
|
||||||
|
|
||||||
|
|
||||||
@ -1,6 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.db.models.signals import post_save |
|
||||||
from models import Article |
|
||||||
from functions.signal_handlers import post_save_handler |
|
||||||
|
|
||||||
#post_save.connect(post_save_handler, sender=Article) |
|
||||||
@ -1,16 +0,0 @@ |
|||||||
""" |
|
||||||
This file demonstrates writing tests using the unittest module. These will pass |
|
||||||
when you run "manage.py test". |
|
||||||
|
|
||||||
Replace this with more appropriate tests for your application. |
|
||||||
""" |
|
||||||
|
|
||||||
from django.test import TestCase |
|
||||||
|
|
||||||
|
|
||||||
class SimpleTest(TestCase): |
|
||||||
def test_basic_addition(self): |
|
||||||
""" |
|
||||||
Tests that 1 + 1 always equals 2. |
|
||||||
""" |
|
||||||
self.assertEqual(1 + 1, 2) |
|
||||||
Loading…
Reference in new issue