Eric Moore

Entry created via API displays raw HTML

Vote 0 Votes

In my quest to bring my eventbrite events into blog entries I wrote some python that parses the XML generated by the eventbrite API and uploads it via PyMT, a python binding for the movable type XMLRPC API.

It works great, but now I am having a problem with HTML being displayed raw in the body of the posting. See:

http://htink.org/htink/blog/2010/08/htink-workshop-arduino-led-motors-and-sensors-1.html

How can I take the HTML from the eventbrite feed and place it directly into a movable type blog entry via xmlrpc?

Thanks for any help, this is almost completed :)

-Eric

Reported on Movable Type 5

2 Replies

| Add a Reply
  • What it's done is it's escaped your HTML. Every < replaced with &lt; for example. You can write a second Python script to load the entries and unescape them or you can do it with Perl. This Perl script should do it (though I claim no warranty since I just hacked it together):

    use strict;
    use lib ('./lib', './extlib');
    use MT;
    use MT::Entry;
    MT->instance();
    
    

    my @entries = MT::Entry->load();

    foreach (@entries) {
    my $text = $_->text();
    $text =~ s/&lt;/</;
    $text =~ s/&gt;/>/;
    $_->text($text);
    $_->save();
    }

  • Here is some python code to parse XML spat out by eventbrite and post an event to movable type, thanks for the help!

    I had to modify the PyMT library by adding dateCreated to the appropriate class.

    from xml.dom import minidom
    from datetime import *
    from PyMT import *

    xmldoc = minidom.parse('eventbrite.rss')
    events = xmldoc.firstChild
    mt = PyMT("http://mt-install/mt/mt-xmlrpc.cgi", "user", "pass")

    def postevent(eventNum):
    myNum = (eventNum * 2) + 1
    title = events.childNodes[myNum].getElementsByTagName('title')[0].firstChild.toxml("utf-8")
    converted = datetime.strptime(events.childNodes[myNum].getElementsByTagName('start_date')[0].firstChild.toxml("utf-8"), "%Y-%m-%d %H:%M:%S")
    description = events.childNodes[myNum].getElementsByTagName('description')[0].firstChild.toxml("utf-8")
    description = description.replace("<", " description = description.replace(">", ">")
    description = description.replace(""", "\"")
    description = description.replace("&", "&")
    url = events.childNodes[myNum].getElementsByTagName('url')[0].firstChild.toxml("utf-8")
    mydesc = '\n\n'.join ([description, url])
    mytime = converted.strftime("%Y-%m-%d %H:%M:%S")
    mt.newPost(2, {'title':title, 'description':mydesc, 'categories':[4], 'dateCreated':mytime}, 1)


    postevent(0)

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1774 6167

Last Topic: Template modules by Zielun on Feb 16, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1434 5088

Last Topic: Maintenance announcement by Nick on Feb 17, 2012

695 2912

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

174 740

Last Topic: Captcha images rendering slowly by ScottM on Feb 12, 2012

190 568

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012