Friday, February 29, 2008

We wrote our own commenting system and wanted to extract all of our comments for all our page back out of JSKit.

Some code and notes here written in C# and here it is (notes are a few months old so I am just getting around to putting them up, sorry.) Note: Dont pound on the JSKit servers as

If you have comments in JKit one item that you might have noticed is that you can't get your data back so I put together this little bit of .Net code that will help. The dataformat across the web is JSON and this regular expression will parse it out for you.

wwHttp() is a bit of code that you can find here..One addition... Change the Encoding from 1252 to 65001 to support UTF-8 extended languages like Russian and one other thing... Create a app.config file with the following data (needed for running this code on a Win2k3 box)

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>
</configuration>

There is some date calculation as well.. This should help

DateTime d1;

double test = 0;

string exacttime = "";

d1 = new DateTime(1970, 1, 1);

test = 1171898391;

test = test * 1000;

d1 = d1.AddMilliseconds(test);

exacttime = d1.ToShortDateString() + " " + d1.ToLongTimeString();

string getDataFor = System.Web.HttpUtility.UrlEncode("http://orisndev01.amr.corp.intel.com/ISN/Home/Test.htm");

string URL = "http://js-kit.com/comments-data.js?ref=" + getDataFor;

string regex = @"{sID:.*?status:s'(.*?)'.*?Name:s'(.*?)'.*?Text:s'(.*?)'.*?}";

System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Singleline)

| System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options);

wwHttp loHttp = new wwHttp();

//loHttp.ProxyAddress = "http://xxxxxxxx.xx.xxxxx.com:911";

string testtxt = loHttp.GetUrl(URL);

testtxt = testtxt.Replace("\'","&apos;"); Fixes single quote problem in regexp

//string testtxt = " var data = [{ ID: 'jsid-1174938750-0', yours: true, status: 'A', TS: 1174938750, Name: 'Kevin', Text: 'I like this? URL Changed and the comment was lost though...'} ,";

foreach( System.Text.RegularExpressions.Match m in reg.Matches(testtxt))

{

string cStaus = m.Groups[1].Value; // cStaus = "A" is the only good one...

string cName = m.Groups[2].Value;

string cComment = m.Groups[3].Value;

string stopme2 = "";

}

Kevin

No comments:

Blog Archive