Пример #1
0
def convert(mtfile, urlbase, forum):
    entries = mt.parse_export(mtfile)

    disqus = Disqus()
    for e in entries:
        if "comment" in e:
            for c in e["comment"]:
                url = make_url(urlbase, e)
                title = e["metadata"]["title"]

                thread = disqus.get_thread_by_url(forum, url)
                if not thread:
                    thread = disqus.thread_by_identifier(forum, title, title)
                disqus.update_thread(forum, thread["id"], title=title, slug=e["metadata"]["basename"], url=url)

                disqus.create_post(
                    forum,
                    thread["id"],
                    c["data"],
                    c["author"],
                    c.get("email", "anonymous"),
                    c.get("url"),
                    c["ip"],
                    c["date"],
                )
Пример #2
0
def convert(mtfile, postpath):
    entries = mt.parse_export(mtfile)
    
    # convert posts to jekyll format
    for e in entries:
	if e['metadata']['status'] == 'Draft':
	    continue

	postname = '%s-%s' % (e['metadata']['date'].strftime("%Y-%m-%d"),
			      e['metadata']['basename'])
	postname += '.markdown'
	
	f = open(os.path.join(postpath, postname), 'w')

	f.write('---\n')
	f.write('layout: post\n')
	if re.search('[-:"]', e['metadata']['title']):
	    f.write('title: "%s"\n' % \
			e['metadata']['title'].replace('"', '\\"'))
	else:
	    f.write('title: %s\n' % e['metadata']['title'])
	if 'tags' in e['metadata']:
	    f.write('tags: [%s]\n' % e['metadata']['tags'].replace(',', ', '))
	f.write('time: "%s"\n' % e['metadata']['date'].strftime('%H:%M'))
	if 'extended body' in e:
	    f.write('extended: ":EXTENDED:"\n')
	f.write('---\n\n')

	f.write(e['body']['data'])

	if 'extended body' in e:
	    f.write('\n:EXTENDED:\n\n')
	    f.write(e['extended body']['data'])

	f.close()