Automating KiGG Submission

by KodefuGuru 30. July 2009 18:35

This is part 3 of a series on KiGG Automation. Code in this article may be dependent on previous entries.

Part 1: Automating KiGG Publishing
Part 2: KiGG’s Story Summary 
Part 3: Automating KiGG Submission

When you’re first starting a KiGG site and your user base is low, creating a bot can ease the pain of obtaining content. However, in the default install of KiGG there is no way to automate this. You can search blogs and news sites, but submitting articles from those sites is a manual process; even for the sources you trust.

My goal in this article is to build off of the first article so that submission can be automated. There are many sources of content out there, and I may cover some aspects of retrieving this in future articles. But for now, that it is up to you to explore.

Finding the submit route is pretty simple: it is Submit and it is handled by the StoryController.

_routes.MapRoute("Submit", "Submit", 
    new { controller = "Story", action = "Submit" });

The method on the controller makes it clear what http method we must use and the parameters required.

[AcceptVerbs(HttpVerbs.Post), ValidateInput(false), Compress]
public ActionResult Submit(string url, 
    string title, string category, string description, string tags)

Analyzing this method shows that another JSON class can be used: JsonCreateViewData. We will need to add this to our bot’s codebase. It uses two properties already found on KiggResult, so we will call this KiggCreateResult and derive from the former class.

public class KiggCreateResult : KiggResult
{        
    [JsonProperty(PropertyName = "url")]
    public string Url { get; set; }

    public static KiggCreateResult Create(string json)
    {
        return JsonConvert.DeserializeObject<KiggCreateResult>(json);
    }
}

Now, inside KiggBot.cs, we will need to add our submit method. I think it may be better to return the url to the story here, but I’ll worry about refactoring this later. Remember that HttpDictionary will handle the form encoding for us.

public bool Submit(string storyUrl, string title, 
    string category, string description, string tags)
{
    HttpDictionary dictionary = new HttpDictionary { 
        {"url", storyUrl}, 
        {"title", title},
        {"category", category},
        {"description", description},
        {"tags", tags}
    };

    var result = KiggCreateResult.Create(
        session.Post(url + "Submit", dictionary));

    return result.IsSuccessful;
}

That seemed easy enough. Now, in the test program I will call this with a few parameters to see how it works.

KiggBot bot = new KiggBot("http://localhost:1736");
bot.Login("bee", "iambusy");
bot.Submit("http://example.com/", "Example", "Agile", 
    "This is a test", "Example, News");
bot.Logout();

No dice. I received an error that the user agent must be set. I think user agent should be configurable in our program, but for simplicity I will add a constant to WebSession for userAgent and set it on the request object in the Post method.

private const string userAgent = "Pigg";
public string Post(string url, string formData)
{
    var request = WebRequest.Create(url) as HttpWebRequest;
    request.UserAgent = userAgent;
    ...
}

I tried again, and it worked perfectly. The bot created an entry with two new tags: Example and News. Keep in mind that Category must match a valid category in your KiGG install.

If you’re following along, you can now automate KiGG publishing and article submission. You can also define what part of the html from which the story summary is retrieved. Leave a comment on what part of KiGG automation you would like me to look at next.

Tags: , ,

Comments

7/30/2009 6:39:13 PM #

trackback

Trackback from DotNetKicks.com

Automating KiGG Submission

DotNetKicks.com

7/30/2009 6:41:05 PM #

trackback

Trackback from DotNetShoutout

Automating KiGG Submission

DotNetShoutout

7/31/2009 7:27:44 AM #

Muhammad Mosa

Good post, What about building few sample application or tools for kigg and collect features such as automated publishing & submittion to be part of those samples.
Maybe build them as background tasks that run based on schedule?

Muhammad Mosa Egypt

7/31/2009 10:12:01 AM #

chris

That is where I'm going with this, but I think it may be best to wrap it up in a class library like Google's API (then add tools).

chris United States

7/31/2009 1:56:10 PM #

trackback

Trackback from NewsPeeps

Automating KiGG Submission

NewsPeeps

8/19/2009 3:34:06 PM #

Jason

Chris, this is a nice series. Thanks for the post and keep up the good work.

Jason United States

9/7/2009 8:05:48 PM #

Antonio Chagoury

Now, if only you could get around the CAPTCHA control for new unverified users Smile ...

I guess that would have to be a pre-requisite for those who would want to use PiGG.

Antonio Chagoury United States

9/7/2009 9:08:38 PM #

Chris

Bot users don't get the captcha control =). It would be up to the owner of the site whether they want to allow you to use it or not. It seems to be working great so far, but it requires removing the concept of categories. I replaced the menu with week's most popular tags. I will be changing Category to Media Type and will get allow videos from YouTube to be submitted and embedded.

Chris United States

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen

Whois KodefuGuru

Chris Eargle

Chris Eargle
.NET Community Champion

LinkedIn Twitter Technorati Facebook

MVP - Visual C#

 

INETA Community Champions
Friend of RedGate
Telerik .NET Ninja
Community blogs & blog posts

I am a #52er


World Map

RecentComments

Comment RSS

Tag cloud

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010