Created
June 24, 2011 22:35
-
-
Save ipmb/1045818 to your computer and use it in GitHub Desktop.
Quick and dirty script to export django.contrib.comments as an IntenseDebate Export file to import it in Disqus.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.html import escape | |
from django.contrib.comments.models import Comment | |
from django.utils.encoding import smart_str | |
post = u'' | |
for i in Comment.objects.order_by('submit_date'): | |
if not i.content_object: | |
continue | |
post += u""" | |
<blogpost> | |
<url>%(url)s</url> | |
<title>%(title)s</title> | |
<guid>%(slug)s</guid> | |
<comments> | |
<comment> | |
<isAnon>1</isAnon> | |
<name>%(name)s</name> | |
<email>%(email)s</email> | |
<url>%(curl)s</url> | |
<ip>%(ip)s</ip> | |
<text>%(text)s</text> | |
<date>%(date)s</date> | |
<gmt>%(date)s</gmt> | |
<score>1</score> | |
</comment> | |
</comments> | |
</blogpost> | |
""" % { | |
'url': 'http://www.mahner.org'+i.content_object.get_absolute_url(), | |
'title': i.content_object.title, | |
'slug': i.content_object.slug, | |
'name': i.name or u'Anonymous', | |
'email': i.email or u'[email protected]', | |
'curl': i.url, | |
'text': escape(smart_str(i.comment)), | |
'ip': i.ip_address, | |
'date': i.submit_date.strftime('%Y-%m-%d %H:%M:%S'), | |
} | |
post = u'<output>%s</output>' % post | |
post = post.encode('UTF-8') | |
f = open('test.txt', "w") | |
f.write(post) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment