David S.

upload and publish entry programmatically

Vote 0 Votes

Hey folks. I am new to MT and trying to take a backend feed and some templating and auto generate and publish new blog entries from it. I am using MT 4.x and have played a bit with just interacting directly with the URLs I see using firebug. But there seem to be odd sequencing and maybe permission problems with this approach. So basically, any suggestions to accompish this auto-publishing are greatly appreciated.

Peace,
David S.

Reported on Movable Type 4.25

6 Replies

| Add a Reply
  • Hi David,

    What is your goal?

    Would you like to have posts scheduled to go live at given times?

    If that is the case, then you could create new entries and schedule them to be published at various times in the future.

    Then you could create a cron job which to run the "run-periodic-tasks" script.

    More details from:
    http://www.movabletype.org/documentation/administrator/setting-up-run-periodic-taskspl.html

    Kind Regards,
    Mihai Bocsaru

    ----------------------------------
    Daily Movable Type Consultant

    Web Development
    Movable Type Consulting
    Six Apart Partner

    http://www.pro-it-service.com/
    ----------------------------------

    Movable Type Demo
    http://www.movabletypedemo.org/
    ----------------------------------

    Open Melody Demo
    http://www.openmelodydemo.org/

  • Thanks for your answer. I actually want to generate the entries themselves from a template and a data feed. That results in a text file in markdown format. I want to then programatically import that file and have it published. No human intervention at all. Just a recurring scheduled job.

    Thanks for any more help.

  • Then you would have a code a plugin which to do that.

    I've done this for a different scope, which was to feed a blog from an XML document.

  • Thanks again for the advice. I have 1 last question about this other approach I was trying:

    From a simple Python script I can login and import an entry, but it does not actually get published though it says it is published.

    I figured I would just hack it to republish everything but despite have the right cookies and magic_token in the params *and* the same user credentials that I use to publish from a browser, I get 'No permissions'.

  • Solved. I found tools/rebuild_pages and used that to inform the Rebuild stage. Easier than I thought actually. Didn't realize I could just pass credentials in the params for each call.

    Thanks much!

    Below is some Python code using the requests library.

    import re
    import requests
    
    

    username, password = 'foo', 'bar'
    blog_id = 1

    ### Import

    url = "http://localhost/mt-cgi-bin/mt.cgi"
    requests.post(url, files={'file': open('test.md')}, data=dict(
    __mode='import',
    blog_id='1',
    import_type='import_mt_format',
    wp_path='wp-content/uploads',
    mt_site_path='1',
    mt_extra_path='',
    title_start='',
    title_end='foo',
    default_status='',
    import_as_me='0',
    convert_breaks='markdown',
    encoding='guess',
    default_cat_id='',
    username=username,
    password=password
    ))

    ### Rebuild

    build_type = 'index'
    next = 0
    total_entries = 10
    offset = 0
    limit = 20
    entry_id = 1

    next_url = re.compile("window\.location='(.*)'")

    url = "http://localhost/mt-cgi-bin/mt.cgi?__mode=rebuild&blog_id={blog_id}&type={build_type}&next={next}&offset={offset}&limit={limit}&total_entries={total_entries}&entry_id={entry_id}".format(**locals())

    while True:
    url += "&username={0}&password={1}".format(username, password)
    resp = requests.get(url)
    url = next_url.search(resp.content)
    if not url:
    print 'done'
    break
    url = url.groups()[0]
    print url

  • You're welcome! Congratulations for this.

    If you check also the other tools, you would see they are very useful for various actions.

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