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.
56 lines
2.1 KiB
56 lines
2.1 KiB
# coding=utf-8
|
|
import datetime
|
|
import os
|
|
import django
|
|
import sys
|
|
|
|
start = datetime.datetime.now()
|
|
sys.path.append("/var/www/projects/codemy/")
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
|
|
from courses.models import Lesson
|
|
from lms.tools import show_progress
|
|
|
|
result = open('lessons_comments_hc.xml', 'w')
|
|
result.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
result.write('<hc>\n')
|
|
all = 0
|
|
n = 0
|
|
|
|
for l in Lesson.objects.all():
|
|
all += l.comments.count() if l.comments.exists() else 0
|
|
|
|
print('Количество комментариев: %s' % all)
|
|
|
|
for lesson in Lesson.objects.all():
|
|
if lesson.comments.exists():
|
|
result.write('<post>\n')
|
|
result.write('<title>{0} / {1}</title>\n'.format(lesson.course.get_title(), lesson.get_title()))
|
|
result.write('<url>http://go.skillbox.ru/courses/lesson/{0}</url>\n'.format(lesson.id))
|
|
result.write('<comments>\n')
|
|
|
|
for comment in lesson.comments.all():
|
|
result.write('<comment>\n')
|
|
result.write('<id>{0}</id>\n'.format(comment.id))
|
|
result.write('<parent_id>{0}</parent_id>\n'.format(comment.parent_id))
|
|
result.write('<root_id>{0}</root_id>\n'.format(comment.get_root_id() if comment.get_root_id() else ''))
|
|
result.write('<text>{0}</text>\n'.format(comment.get_text()))
|
|
result.write('<nick>{0}</nick>\n'.format(comment.owner.get_name()))
|
|
result.write('<time>{0}</time>\n'.format(''))
|
|
result.write('<ip>{0}</ip>\n'.format(comment.owner.get_ip()))
|
|
result.write('<account_id>{0}</account_id>\n'.format(comment.owner.id))
|
|
result.write('<topic>{0}</topic>\n'.format('true' if comment.owner.is_admin else 'false'))
|
|
result.write('<avatar>{0}</avatar>\n'.format(comment.owner.get_image_url()))
|
|
result.write('</comment>\n\n')
|
|
show_progress(all, n)
|
|
n += 1
|
|
|
|
result.write('</comments>\n')
|
|
result.write('</post>\n')
|
|
|
|
result.write('</hc>')
|
|
|
|
|
|
finish = datetime.datetime.now()
|
|
print('\nTIME: %s seconds' % (finish-start).seconds) |