# 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('\n') result.write('\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('\n') result.write('{0} / {1}\n'.format(lesson.course.get_title(), lesson.get_title())) result.write('http://go.skillbox.ru/courses/lesson/{0}\n'.format(lesson.id)) result.write('\n') for comment in lesson.comments.all(): result.write('\n') result.write('{0}\n'.format(comment.id)) result.write('{0}\n'.format(comment.parent_id)) result.write('{0}\n'.format(comment.get_root_id() if comment.get_root_id() else '')) result.write('{0}\n'.format(comment.get_text())) result.write('{0}\n'.format(comment.owner.get_name())) result.write('\n'.format('')) result.write('{0}\n'.format(comment.owner.get_ip())) result.write('{0}\n'.format(comment.owner.id)) result.write('{0}\n'.format('true' if comment.owner.is_admin else 'false')) result.write('{0}\n'.format(comment.owner.get_image_url())) result.write('\n\n') show_progress(all, n) n += 1 result.write('\n') result.write('\n') result.write('') finish = datetime.datetime.now() print('\nTIME: %s seconds' % (finish-start).seconds)