Export the blog in the blog Park as the text format of MovableType, movabletype

Source: Internet
Author: User
Tags movable type wordpress blog

Export the blog in the blog Park as the text format of MovableType, movabletype

Recently deleted the previous wordpress blog, and re-built an independent blog with textpattern, http://www.shenlongbin.com, it can be used as a backup of the content on the blog garden, however, it is very difficult to import many of my previous articles. After some tossing, I finally exported the content of the blog garden as text and then imported it into textpattern.

Step 1: C # program to read the blog garden content

The management end of the blog park provides the blog backup function to generate an xml file. However, it can only back up the main content of the blog, and does not contain the blog's abstract information and keyword information, you must use metaweblogAPI for access to obtain detailed information. Quick learning of metaweblog programming knowledge, internal use of XML-RPC calls, from the Internet to search for relevant information and class libraries. Download secret (. NET framework 2.0. The original address is here: http://xmlrpcnet.googlecode.com/files/xml-rpc.net.2.5.0.zip. Big CC has an article about metaweblogAPI. In addition, this article introduces the calling method. You only need to modify it a little bit to get the bloggers from the blog Park.

You can access the metaweblog access interface at http://www.cnblogs.com/speeding/services/metaweblog.aspx. In fact, you can find the definition of the main class or structure in the interfaces/MetaWeblogAPI. cs file in the xml-rpc.net2.5.0 compressed package, just add or modify it slightly.

    [XmlRpcMissingMapping(MappingAction.Ignore)]    public struct Post    {        [XmlRpcMissingMapping(MappingAction.Error)]        [XmlRpcMember(Description = "Required when posting.")]        public DateTime dateCreated;        [XmlRpcMissingMapping(MappingAction.Error)]        [XmlRpcMember(Description = "Required when posting.")]        public string description;        [XmlRpcMissingMapping(MappingAction.Error)]        [XmlRpcMember(Description = "Required when posting.")]        public string title;        public string[] categories;        public Enclosure enclosure;        public string link;        public string permalink;        [XmlRpcMember(           Description = "Not required when posting. Depending on server may "           + "be either string or integer. "           + "Use Convert.ToInt32(postid) to treat as integer or "           + "Convert.ToString(postid) to treat as string")]        public object postid;        public Source source;        public string userid;        public object mt_allow_comments;        public object mt_allow_pings;        public object mt_convert_breaks;        public string mt_text_more;        public string mt_excerpt;        public string mt_keywords; // add by shenlb, for cnblogs        public string wp_slug;     // add by shenlb, for cnblogs;    }

 

Our Organization needs to use a proxy and password verification to access the Internet. Therefore, we need to add several lines of key code:

MetaWeblogCnblogs blog = new MetaWeblogCnblogs();blog.Url = "http://www.cnblogs.com/speeding/services/metaweblog.aspx";Uri proxyURI = new Uri("http://myproxyhost.myproxydomain.com:80");System.Net.WebProxy proxyObject = new System.Net.WebProxy(proxyURI, false);proxyObject.Credentials = new System.Net.NetworkCredential("proxy_username", "proxy_password");blog.Proxy = proxyObject;Post[] posts = blog.getRecentPosts("speeding", "speeding", "my_blog_admin_password", 50);


In this way, you can obtain the Blog content, but you need to call getPost to obtain detailed information. Here you can see the abstract and keywords.

Post detail = blog. getPost (post. postid. ToString (), "speeding", "my_blog_admin_password ");

Step 2: Use pandoc to convert html content to textile tag

Description in Post is html Tag, while textpattern uses textile by default. Therefore, you need to convert it to textile. For more information about textile tag, see here.

The famous pandoc is used here. This magic tool is actually written in haskell. When I learned the haskell language, I thought it was just a teaching language. Someone wrote a utility!

Write the content in the blog to the temp.html file, and use the following command line to convert it.

Pandoc.exe-t textile-o textile.txt temp.html

Main Code:

ProcessStartInfo startInfo = new ProcessStartInfo();startInfo.CreateNoWindow = false;startInfo.UseShellExecute = false;startInfo.FileName = "..\\..\\pandoc.exe";startInfo.WindowStyle = ProcessWindowStyle.Hidden;startInfo.Arguments = "-t textile -o textile.txt temp.html";using (Process exeProcess = Process.Start(startInfo))            {     exeProcess.WaitForExit(); }    return File.ReadAllText("textile.txt"); 
Step 3: generate the import.txt File

After processing several hundred articles and documents, add them to the import.txt file, and save the last file with UTF8.

Movable Type blog text format instructions can be viewed here: https://movabletype.org/documentation/appendices/import-export-format.html#example

Simple Description: The file is stored in UTF-8 encoding. the first few lines are single-line text information, and the following BODY, KEYWORDS, and EXCERPT are multi-line text, multi-line text must be separated by five short and horizontal lines. each article is separated by eight short and horizontal lines. The simplest example is as follows:

TITLE: A dummy title

AUTHOR: shenlongbin

DATE: 01/31/2012 03:31:05 PM

Primary category: reading

CATEGORY: reading

-----

BODY:

This is the body.

Another paragraph here.

Another paragraph here.

-----

EXCERPT:

See, this entry does not have an extended piece; but it does have an excerpt. It is special.

-----

--------

Key code:

IFormatProvider culture = new CultureInfo ("en-US", true );

String date = post. dateCreated. ToString ("dd/MM/yyyy hh: mm: ss tt", culture); // 08/05/2002 04:05:23 PM

Part 4: Upload the import.txt file and import it

The file must be stored in public_html/textpattern/include/importDirectory, and the file name must beimport.txt。In fact, the management end of textpattern can import blogs in the formats of Movable Type (File/MySQL), Blogger, b2, and WordPress. However, only Movable Type and Blogger can be imported into text files.

Run the import operation on the textpattern management interface. A list of blog articles is displayed when the import is successful.

Others

Previously, I used the blog_backup applet to back up my blog. Now I found that my own mini-app can be backed up more thoroughly and can be slightly modified and exported to wordpress. I learned some of these knowledge points: movableType, metaweblog, xml-rpc, textile, pandoc, c # culture in date. ToString (), WebProxy ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.