As I've mentioned in the past, because I spend so much of my time in a browser, I've
taken the time to build my own customized start page that runs on my local web server.
It contains a number of things that I use on a fairly regular basis. These include
search forms for my favorite search engines, a page containing dns, ip addresses, and
connection details for my servers, links to sites I visit daily, links to my
router config screens, etc. So what's the point? The point is that now it's going to
contain the latest headlines from MegaTokyo as well.
There are RSS feeds for everything these days. So why did it take me this long to write
an ASP script to read one? Simple... because I'm lazy and until now there wasn't a feed
I wanted on my homepage. Why did I use classic ASP instead of ASP.NET? Two reasons: there
are already scripts everywhere to do this in ASP.NET, and my homepage is still running on
classic ASP. I know I could easily convert it, but I think the answer to the first question
already adequately covers why I haven't.
To be honest, there's nothing special about the code... it'll work with most any RSS feed.
I've done a few things specific to MegaTokyo's feed (like replacing <br>s with <br />s
for XHTML compliance), but there's really no reason you couldn't use this script with any
RSS feed. In fact, we use a very similar script on our homepage to pull in the headlines
from DevX's .NET feed. (Before you write, asking me to add headlines for your site, please note that
DevX is also owned by Jupitermedia).
Before I give you the code, I'd like to mention that it includes no caching. This is not a
big deal for my intended usage (because my homepage is hit only by me and really only a few times a day),
but if you were to put this on a heavily trafficked page, you should absolutely add some form
of caching. It will make your pages faster and will lessen the
load on the server providing the RSS feed. For more information on an easy way to do this,
see my article A Simple Method for Caching HTTP Requests.
If you change the code below to build your HTML in a string instead of Response.Writing it directly out to the browser,
the caching code can be used almost exactly as it is.
So without any further rambling on my part, here's the code:
Update: I tried using the non-cached version and was just about to pull all my
hair out. Apparently I hit my start page more then I was giving it credit and I'm used to it just
popping right in instantly. At times the MT servers were slow and it was killing me. Anyway, since I
modified my version to cache, I figured I might as well post the caching version here as well.
It's nothing sophisticated, it just copies the output text to an application var and uses that
instead of making any new HTTP requests for a few hours.
A copy of the old version is still available in the zip file if you need it for some reason,
but the code listing below does include caching.
<%@ Language="VBScript" %>
<% Option Explicit %>
<% Response.Charset = "UTF-8" %>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>ASP 101's MegaTokyo RSS Feed Reader</title>
If DateDiff("h", Application("MegaTokyoUpdated"), Now()) >= 2 _
Or Request.QueryString("force") <> "" Then
Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXML.async = False
objXML.setProperty "ServerHTTPRequest", True
If objXML.parseError.errorCode <> 0 Then
Response.Write "<pre>" & vbCrLf
Response.Write "<strong>Error:</strong> " & objXML.parseError.reason
Response.Write "<strong>Line:</strong> " & objXML.parseError.line & vbCrLf
Response.Write "<strong>Text:</strong> " _
& Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
Response.Write "</pre>" & vbCrLf
Set objItemList = objXML.getElementsByTagName("item")
Set objXML = Nothing
For Each objItem In objItemList
' MegaTokyo Feed childNodes: 0=title, 1=link, 2=description
strHTML = strHTML & "<p>" & vbCrLf
strHTML = strHTML & "<a href=""" & objItem.childNodes(1).text & """>"
strHTML = strHTML & "<strong><em>" & objItem.childNodes(0).text
strHTML = strHTML & "</em></strong></a><br />" & vbCrLf
strHTML = strHTML & Replace(objItem.childNodes(2).text, "<br>", "<br />") & vbCrLf
strHTML = strHTML & "</p>" & vbCrLf
Set objItemList = Nothing
Application("MegaTokyoContent") = strHTML
Application("MegaTokyoUpdated") = Now()
<%= Application("MegaTokyoContent") %>
<!--<%= Application("MegaTokyoUpdated") %>-->
I did very little work on the formatting, since anyone who uses the script
will probably want to modify the output to match their site. The output is pretty
much plain vanilla HTML, but here's what it looks like anyway:
After finishing the comic last night, i sat down and foolishly watched the first two episodes of Samurai 7, a new anime series by Gonzo roughly based on Akira Kurosawa's classic film Seven Samurai. Sorta like Ghost in the Shell meets an old fasion samurai flick...[read rant]
So I'm typing this rant with one hand (no jokes until you finish the sentence, please) because with my left hand, I'm playing City of Heroes. I have 89 more minutes to rescue a group of mystics from the nefarious clutches of the Circle of Thorns, and I haven't a moment to lose--if I dillydally even a moment, they may not survive the night... [read rant]
One of the things that I've noticed about myself is that I am very much a creature of habit. For instance, when I find a dish at a restaurant that I like, I will order the same thing every single time I go there. Habits are hard to change, it's a lot like trying to divert a stream - it takes a lot of digging, engineered fill and concrete pipes to encourage it to go somewhere else...[read rant]
The last rant I wrote late at night was a disaster. I was so embarrassed when I went back later and saw all the typos, misspellings, and dropped words. Piro proofread it for me too. Last time I ask him....[read rant]
I suppose the best way to test this thing is to actually let it loose in the wild and see how much damage it does. ^^;;
I'm anticipating a lot of 'how do i use this RSS thing?' questions that the link i provided will not really answer adequately for the less technically savvy, so any suggestions of websites and readers to refer people to will be welcome.
Hi, welcome to the first implimentation (read as "manually updated and maintained") RSS feed for Megatokyo.
It's a pretty simple feed for now, but the intent is to experiment to see how well this can work for the site. Basically, by keeping an eye on this feed, you will be alerted to changes on the Megatokyo website (new comic, new rants) the Fredart site (new sketches, etc) and the Megagear store (when it finally opens :P)
This is a manually updated RSS feed, so i will have to update things by hand for a while, but when the new site is done, most things should be automated.
All feedback and comments appreciated. I hope you find this new feature to the Megatokyo website useful!
Note that the above is not being generated dynamically. It's just a sample run of the code from which I cut and pasted the HTML.
Now that MegaTokyo is publishing thumbnails, I've hacked (meaning bad code... I'm not responsible when it breaks!)
together a new format for my homepage. Here's a sample: