|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Sun Apr 01, 2007 5:16 am
RSS feed |
zMud 7.21 WinXP
Is there anyway to parse data from an RSS feed, and put it into a stringlist in zMud?
mercatroid |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Apr 01, 2007 11:11 am |
Since zMUD can't read RSS itself you'll need a program that does read RSS feeds and then gives you access to the results via COM. You can then use zMUD's COM capabilities to access the feed via the reader program.
|
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Sun Apr 01, 2007 11:34 am |
Yeah!
I'm actually working on a JScript COM component to do it for you Mercatroid.
If you don't find something else you want to use in the mean time, I should have something for you sometime today.
If you can give me a few urls to specific rss feeds you're gonna look at, I can test my code on them |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Mon Apr 02, 2007 6:18 pm |
Hey Okay so I'm a little late, but it works.
At least for me :p I really hope it does what you want.
Place the code below into a file named RSS2ZMUD.WSC and save it somewhere it Wont be deleted, ie your zMud directory.
Code: |
<?xml version="1.0" ?>
<package>
<comment>
Dharkael's attempt at a RSSReader for zMud
</comment>
<component id="RSS2ZMUD">
<?component error="true" debug="true" ?>
<registration progid="RSS2ZMUD.WSC" classid="{42700EC0-77E9-45F7-B170-14C46C6799F5}" description="RSS2ZMUD" version="1.0">
</registration>
<public>
<property name="UserName">
<get/>
<put/>
</property>
<property name="Password">
<get/>
<put/>
</property>
<property name="URL">
<get/>
<put/>
</property>
<property name="IsValidData">
<get/>
</property>
<property name="Data">
<get/>
</property>
<property name="HTTPStatus">
<get/>
</property>
<property name="XMLStatus">
<get/>
</property>
<property name="ErrorText">
<get/>
</property>
<method name="GetFeed">
</method>
</public>
<reference id="XSLTemplate" guid="{F5078F18-C551-11D3-89B9-0000F81FE221}" version="3.0"/>
<script id="RSS2ZMUD" language="JScript">
<![CDATA[
var description = new RSS2ZMUD;
function RSS2ZMUD()
{
this.get_ErrorText = get_ErrorText;
this.get_XMLStatus = get_XMLStatus;
this.get_HTTPStatus = get_HTTPStatus;
this.GetFeed = GetFeed;
this.get_Data = get_Data;
this.get_IsValidData = get_IsValidData;
this.get_URL = get_URL;
this.put_URL = put_URL;
this.get_Password = get_Password;
this.put_Password = put_Password;
this.get_UserName = get_UserName;
this.put_UserName = put_UserName;
}
var UserName = "";
function get_UserName()
{
return UserName;
}
function put_UserName(newValue)
{
UserName = newValue;
}
var Password = "";
function get_Password()
{
return Password;
}
function put_Password(newValue)
{
Password = newValue;
}
var URL = 0;
function get_URL()
{
return URL;
}
function put_URL(newValue)
{
URL = newValue;
}
var IsValidData = false;
function get_IsValidData()
{
return IsValidData;
}
var Data = "";
function get_Data()
{
return Data;
}
function GetFeed()
{
IsValidData = false;
Data ="";
XMLStatus =0;
HTTPStatus =0;
var hmlData = getRssFeed();
var procData;
if(HTTPStatus==200)
{
procData=processRssFeed(hmlData);
if(XMLStatus!=0)
{
var arAlpha = new Array();
for(i in procData)
{
arAlpha.push( map2ZDB(procData[i],false) ); // the news items themselves are in zmud record variable format, and pushed onto array;
}// for i in procData
Data = map2ZDB(arAlpha,true); // now that array has been mappped to zmud style // items are now nested zmud db variable type;
IsValidData = true; // all done signal everything lovely
ErrorText="";
return true;
}//if XMLStatus
}//if HTTPStatus
IsValidData = false;
return false;
}
var HTTPStatus = 0;
function get_HTTPStatus()
{
return HTTPStatus;
}
var XMLStatus = 0;
function get_XMLStatus()
{
return XMLStatus;
}
var ErrorText = 0;
function get_ErrorText()
{
return ErrorText;
}
//Helper Functions/Variables Below, Not Exposed to COM;
function getRssFeed()
{ HttpStatus =0;
ErrorText = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
try{
xmlHttp.open("GET",URL,false,UserName,Password);
xmlHttp.send();
HTTPStatus = xmlHttp.status;
}catch(e){
HTTPStatus = xmlHttp.status; // error state
ErrorText = e.message;
}finally
{
if(xmlHttp.status == 200)//OK
return xmlHttp.responseXML.xml;
else
return "";
}
}
function processRssFeed(data) //parses the xml data returned puts into an array of hash maps
{
var doc = new ActiveXObject("msxml2.DOMDocument.3.0");
doc.async = false;
doc.resolveExternals = false;
doc.validateOnParse = false;
XMLStatus =-1;
var lItemCol;
var arrOut =new Array();
if(!doc.loadXML(data))// if it returns false something wrong with the xml;
{
XMLStatus = doc.parseError.errorCode; //not sure what am gonna do with these things;
ErrorText = doc.parseError.reason;
} else // loadXML returned true we're in business
{
lItemCol = doc.getElementsByTagName('item');
for(i=0;i<lItemCol.length;i++)
{
catARR = new Array();
item = lItemCol.item(i);
dict ={}
for(j=0;j<item.childNodes.length;j++)
{
node = item.childNodes.item(j);
if(node.nodeName.toLowerCase()=='category')
{
catARR.push(node.text);
}else
{
dict[node.nodeName] = node.text;
}//if else
}// for
if(catARR.length>0)
dict['category'] = catARR.join("/");
arrOut.push(dict);
}//for
}
XMLStatus = -1;
return arrOut;
};
//utility function to turn an Associative Array to Zmud Db variable
function map2ZDB(hm,wrap)
{
var zStr ="";
var tStr;
var lstr="";
var rstr="";
if(wrap==undefined)
wrap = false;
if(wrap)
{
lstr ="(";
rstr =")";
}
for(var key in hm)
{
tStr ="";
tStr += key + '\x1e'+lstr+hm[key]+rstr;
if(zStr.length>0)
zStr += '\x1d';
zStr += tStr;
}
return zStr;
}
]]>
</script>
</component>
</package>
|
Now right click on it and choose register.
Now its a COM component.
The string in the Data field, after a successful call to GetFeed is actually a zMud DB variable, which contains a nested DB variable for each news item;
Sample usage below
Code: |
#CLASS {RSSReader}
#ALIAS DisplayRSS {
#VAR RSS %comcreate( 'RSS2ZMUD.WSC')
#VAR RSS.URL "%-1"
#COM RSS GetFeed
#VAR RSSDATA @RSS.Data
#LOOPDB @RSSDATA {
#ECHO *******************************
#showdb %val
}
}
#CLASS 0
|
now if i type DisplayRSS "http://feeds.feedburner.com/MudconnectReviews"
I get something like
*******************************
title: Review: God Wars II
link: http://www.mudconnect.com/cgi-bin/prev/review.cgi?rid=23653
description: You coil your legs beneath you, ready to spring.BRDamocles leaps up into the air.BRYou leap up into the air.BRDamocles backflips away from you.BRYou backflip away from Damocles.BRDamocles kicks both feet at your face as he flips backwards. YourBRshimmering aura absorbs the impact of his kick.BRBRYou land, your bare feet slamming down on the paved street.BRDamocles crashes to the paved street.BRYou leap up into the air.BRYou spin around in midair. Damocles somersaults over the store.BRDamocles kicks at your ... (posted: 2007-03-25T19:06:44-05:00)
dc:subject: TMC Mud Reviews
dc:creator: xakarii
dc:date: 2007-03-25T19:06:44-05:00
*******************************
title: Review: Accursed Lands
link: http://www.mudconnect.com/cgi-bin/prev/review.cgi?rid=23688
description: Do you seek balance?BRBRAre you tired of hack-n-slash till your eyes bleed? Are you BRquickly bored with roleplaying mushes with no code to support BReven simple actions? Tired of hoping for that extra 10 zillion exp BRso you can gain yet another level and get your +5 sword of death? BRTired of power posing in a mush and waiting 20 minutes for your BRnext turn to pose? Want to roleplay with code support? Want to BRbe part of a neverending plot?BRBRIf you answered yes to even one of these questions the... (posted: 2007-03-25T19:05:39-05:00)
dc:subject: TMC Mud Reviews
dc:creator: Pstone
dc:date: 2007-03-25T19:05:39-05:00
*******************************
title: Review: Buffy Mud
link: http://www.mudconnect.com/cgi-bin/prev/review.cgi?rid=23674
description: Buffymud is set in the town of Sunnydale, California a few yearsBRafter the end of the show, people who haven't seen the showBRshouldn't worry though, it's basically just this world, but withBRreal supernatural forces, most of whom reside in Sunnydale. There's aBRback story to explain it, but you can read that in the game.BRBROne of the first great things about this game is the amazing level ofBRcreative freedom given to the players, while you are constricted to aBRset of races and classes, you can comp... (posted: 2007-03-12T20:19:17-05:00)
dc:subject: TMC Mud Reviews
dc:creator: Buffy Guy
dc:date: 2007-03-12T20:19:17-05:00
Anyways there ya go. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Wyndle Beginner
Joined: 28 Mar 2007 Posts: 20 Location: < here and there >
|
Posted: Mon Apr 02, 2007 6:51 pm |
Now that it is done you should put it in the finished script section.
|
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Mon Apr 02, 2007 10:59 pm |
Cmud Version of Dharkael's script!
#ALIAS DisplayRSS {
#VAR RSS %comcreate('RSS2ZMUD.WSC')
#CALL %comset(RSS, "URL", %-1)
#CALL @RSS.GetFeed
RSSDATA=@RSS.Data
#CALL %vartype(RSSDATA,5)
#LOOPDB @RSSDATA {
#ECHO *******************************
#showdb %val
}
} |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Mon Apr 02, 2007 11:43 pm |
Very sweet. A minor change though. For both versions.
Change
#showdb %val
To
#showdb %replace(%val,"<BR>",%cr)
I like it. Now maybe I will actually look at a few RSS feeds. I had never done that before. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Tue Apr 03, 2007 12:31 am |
Quote: |
#showdb %replace(%val,"<BR>",%cr) |
I actually had this in my version of the script just forgot to copy it over :p |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Tue Apr 03, 2007 10:46 am |
Yeah I the sample usage was quick and dirty.
I didnt even think to make it CMUD compatible.
I knew after a basic demo you guys would run with it and do all types of fancy stuff with the data.
I have noticed one problem, its not so much a problem with my code, but it could cause some probs.
RSS feeds are mostly in UTF-8 format and since zMud doesn't display them or send them, it could cause issues.
Mostly I've noticed the problem with curly quotes and one could quickly do a replace for char codes 147 & 148 with a "
and 145 & 146 with a single quote '.
However one could go a step further and write a function to replace the Accented characters with their ASCII equiv
I'll probably do something about that soon, if someone doesnt take care of it .
Maybe I'll do that first and then post the complete code on the Finished Script Forum as suggested by Wyndle.
Before I do that though I'd appreciate some feedback, suggestions for improvement.
Maybe Mercatroid can let us know if this is what he needed. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Wed Apr 11, 2007 12:49 pm |
Holy Crap! I haven't had time to come back and check if anyone had figured this out.
Imagine my surprise!
EXTREME thanks to Dharkael, even though I haven't actually tested it yet...:P
Will do so now and let you know.... |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Fri Apr 13, 2007 7:14 am |
I seem to be getting the following error from zMud:
OLE error 800C0005
Doesn't matter which feed I try either.
Thanks |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Fri Apr 13, 2007 8:17 am |
Okay, now I've found a feed that I don't get the OLE error on. I *DID* get the error with your MudConnectReviews feed.
DisplayRSS "http://www.infoplease.com/rss/dayinhistory.rss"
When I try that, it doesn't give me the error....instead, nothing happens at all.
In fact, somewhere along the way it's sending something to my mud, which returns a big Huh??
Not really sure what the problem is... |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Fri Apr 13, 2007 8:27 am |
Gah....actually that feed gives the OLE error too...I had a typo in my string is why it was coming up "Huh??"...
So back to the original problem.
The Com registered fine, and I used the exact sample zMud script you provided.
Any ideas? |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Fri Apr 13, 2007 12:55 pm |
Got it.
I had a stack/buffer overflow in zMud itself...probably as a result of running too many COMs for extended periods of time (I never disconnect from the MUD).
Adding this COM just sent my mem alloc over the edge....:)
Anyway, rebooted and everything works, lol.
Thanks again for the great work. |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Fri Apr 13, 2007 2:54 pm |
One last request.
The feed that I'm actually trying to get this to work on is http://www.infoplease.com/rss/dayinhistory.rss. This is the XML feed for http://www.infoplease.com/dayinhistory
As you can see, the XML feed only has 1 item, whereas the actual site has 7 (today). Additionally, my Google Homepage aggregator gets 4 items from the feed. Basically, they (like many RSS feeds) have an optional syntax that allows you to get just one item (the default), or 2, 3, 4 or however many items there are that day. Like I said, the default is 1, so that's what your COM script gets. I'd like to be able to grab, say...6 or 7 maximum.
Any ideas on how to modify the COM to handle this? |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
mercatroid Wanderer
Joined: 06 Dec 2004 Posts: 59
|
Posted: Fri Apr 13, 2007 9:46 pm |
I'll be damned.
|
|
|
|
|
|