Saturday, March 20, 2010

How to integrate recent news stories into interactive fiction

I'm writing an interactive novel on Facebook, which besides integrating the reader and the reader's Facebook friends into the novel, incorporating the current time, day, and location of the reader, and even using a Google map of the reader's location as the setting, integrates real-world news headlines. Here's how:


1. Google news. Google news makes it easy to search for headlines on a specific topic. For example, type the url http://news.google.com/news?q=j.d. salinger
(it works even with the space between words!)


As you can see, this generates a search listing of the latest news articles on the subject, in descending chronological order. If you want, you can even refine the search by adding other parameters to the url (like news source, region, time period, etc).


2. Use RSS to parse (extract) the title (or other parts of the news story, for that matter).


Quite simply: http://news.google.com/news?q=j.d. salinger&output=rss

With this type of formatting, you can use PHP to pick out the bits of the article you want. In my case, I wanted only the titles. This part of the programming is very standard. Many websites aggregrate content using customized RSS Feeds.


3. Allow the user/reader to pick the topic


This involves some pretty straightforward programming: store a user-inputed string as a variable and put that variable where it needs to go:


$newsstart = "http://news.google.com/news?q=";

$news = $userinput;

$newsend = "&output=rss";

$newsall = $newsstart . $news . $newsend;


4. Do some fancy PHP XML display stuff, and that's it. You get something like:



Sally Salamander looked down at the soggy newspaper on the park bench. It was a [name of newspaper dynamically inserted here!], the [date of the article here!!] edition, yellowed from the sun. The headline said, simply [headline here!!!]

No comments:

Post a Comment