We've worked through the process of taking a full Daily News Post, parsing it out and posting it to the News List Blog. Now, how do we want to handle the daily process of parsing the Daily News? What's the most simple approach? I don't want to have to change the current process or add a lot of work.
Do we need a User Interface? A control panel button to process the Daily News posts individually perhaps?
What about when I have to edit the original Daily News post? We only want to parse and post to the List Blog once, and it usually takes several read-throughs and edits before I can walk away from the day's DN. When the day's issue is done, how do we kick-off the parsing process? Do we use a TextPart-based CSModule of some kind and repost?
We also need a solution that requires as little modification to the site as possible, and preferrably none at all since the Daily News resides on CommunityServer.org.
It was this final requirement that inspired a List Builder CSModule approach that requires no UI, no touching communityserver.org, no textpart trigger to launch the parsing process, and one-step processing.
The CSModule I came up with will sit on the News List Blog site, which can be anywhere. I compose the Daily News in Live Writer, so when the day's issue is done I will use the Live Writer Weblog dropdown to select my News List Blog and post it. The List Builder CSModule takes care of the rest.
The code in the CSModule is simply a modulized version of the code we've talked about before--scrub the post, convert the <LI /> elements as individual items, extract the text in the item's first hyperlink as the item's subject, convert the item to a weblog post object and post it to a blog.
I needed a complete WeblogPost object in this module. (IContent) content is passed as a parameter to the PrePostUpdate event handler, with the WeblogPost object a base object of content, so we access it with
WeblogPost weblogpost = content as WeblogPost;
Once we do that we can not only get to the weblogpost properties but to its Weblog object as well. Here's the CSModule PrePostUpdate event method.
private void csa_PrePostUpdate(IContent content, CSPostEventArgs e)
{
if (e.ApplicationType == ApplicationType.Weblog && e.Target == PostTarget.Web)
{
WeblogPost weblogpost = content as WeblogPost;
Weblog weblog = weblogpost.Weblog;
string appKey = weblog.ApplicationKey;
if (appKey == ResourceManager.GetString("FaqListAppKey"))
{
string subjectCheckString = ResourceManager.GetString("FaqSubjectCheckString");
if (weblogpost.Subject.IndexOf(subjectCheckString) != -1)
{
CreateFaqListPosts(HtmlScrubber.Clean(content.FormattedBody, false, true),
weblogpost, weblog);
weblogpost.IsApproved = false;
}
}
}
}
Then we walk through the full Daily News post--the same process used in the HtmlScrubber--to create a new WeblogPost from each item, assign our properties, and post it to the List blog.
Weblog _faqListWeblog = Weblogs.GetWeblog(ResourceManager.GetString("FaqListAppKey"));
_wp.Subject = Clean(_subject);
_wp.Body = _singlePost;
_wp.Username = _parentWeblogPost.Username;
_wp.SectionID = _faqListWeblog.SectionID;
_wp.ParentID = 0;
_wp.BlogPostType = BlogPostType.Post;
_wp.PostID = -1;
_wp.IsAggregated = true;
_wp.IsCommunityAggregated = false;
_wp.IsApproved = false;
_wp.Name = _subject;
_wp.PostType = PostContentType.HTML;
_wp.UserTime = _wp.PostDate = DateTime.Now;
WeblogPosts.Add(_wp);
The complete source for the CSModule Builder Class is located here.
NEXT UP! Batching all of the existing Daily News posts and getting them into a News List Blog prototype site somewhere. I want to make sure I can transfer all existing DN posts before implementing the daily process I'm describing here. Not to worry, that's already begun with the MetaBlogAPI giving me the flexibility I need to do a remote transfer from CS.org to a prototype site or when the time comes, to the News List Blog's final destination. Results of MetablogAPI.GetRecentPosts() on the Daily News blog is shown below, so the rest is just typing.
