Hi,
My module generates an information page for each stock I have in the database. I would like to include a block with newsfeed for that particular stock (eg, http://finance.yahoo.com/rss/headline?s=csco). The stock list changes from week to week. So I thought I would do the RSS http request to Yahoo during page generation, and use built-in functions to get, parse, and theme the RSS file. But I don't see any built-in functions to do that. Perhaps I'm not seeing the drupal way. Can someone suggest how this could be done in drupal? Thanks.

Comments

pacoit’s picture

To followup, There is no built-in function. But it's trivial to setup. I created a block and inserted the following code:

// parse url to get stock ticker
$p = explode('/',$_GET['q']);
$ticker = end($p);
$url = 'http://finance.yahoo.com/rss/headline?s='.$ticker;

// retreive RSS and parse
$rss = simplexml_load_file($url);
#$title = (string) $rss->channel->title;
$headlines = "<ul>\n";
foreach ($rss->channel->item as $item)
  $headlines .= "<li><a href='".(string)$item->link."'>" .(string)$item->title."</a></li>\n";
$headlines .= "</ul>\n";

// theme contents in a box in a page region; params: title, contents, region 
echo theme_box("News for: $ticker",$headlines,'right sidebar');

I considered creating a regular drupal configured feed on-the-fly, but resisted thinking ~2k stock feeds would be messy. But, especially when considering the need for caching, it may be the better way in the end.