This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Nixsy's profile picture

atom feed read by computercraft [I have no idea]

Started by Nixsy, 27 August 2012 - 09:48 PM
Nixsy #1
Posted 27 August 2012 - 11:48 PM
Hi guys I wanted to pose the question as after searching I have found nothing on the idea.

Is it possible to read and display atom feeds on a display in game with computercraft?
Nixsy #2
Posted 29 August 2012 - 10:45 PM
I am sorry to bump this but someone must know if it is even possible,

Essentially something like this but inside of computercraft.

https://github.com/slact/lua-feedparser
Kingdaro #3
Posted 29 August 2012 - 11:53 PM
RSS is basically a bunch of blog posts in the form of XML, a markup language which HTML is based off of.

Example rss code:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
	<title>Workbench</title>
	<link>http://www.cadenhead.org/workbench/</link>
	<description>Programming, publishing, politics, and popes</description>
	<docs>http://www.rssboard.org/rss-specification</docs>
	<item>
	  <title>Toronto Star: Only 100 Blogs Make Money</title>
	  <link>http://www.cadenhead.org/workbench/news/3132</link>
	  <pubDate>Mon, 26 Feb 2007 11:30:57 -0500</pubDate>
	  <guid isPermaLink="false">tag:cadenhead.org,2007:weblog.3132</guid>
	  <enclosure length="2498623" type="audio/mpeg"
		  url="http://mp3.cadenhead.org/3132.mp3" />
	</item>
	<item>
	  <title>Eliot Spitzer Files UDRP to Take EliotSpitzer.Com</title>
	  <link>http://www.cadenhead.org/workbench/news/3130</link>
	  <pubDate>Thu, 22 Feb 2007 18:02:53 -0500</pubDate>
	  <guid isPermaLink="false">tag:cadenhead.org,2007:weblog.3130</guid>
	</item>
	<item>
	  <title>Fuzzy Zoeller Sues Over Libelous Wikipedia Page</title>
	  <link>http://www.cadenhead.org/workbench/news/3129</link>
	  <pubDate>Thu, 22 Feb 2007 13:48:45 -0500</pubDate>
	  <guid isPermaLink="false">tag:cadenhead.org,2007:weblog.3129</guid>
	</item>
  </channel>
</rss>

Luckily, lua has some nice string matching functions for you to use. There'd be multiple ways of going about doing this, one would be to get the individual titles and content of certain XML nodes in the text.



local sData = http.get 'http://your.feed/url'

local function find(sNode)
  local tValues = {}
  for sText in sData:gmatch(string.format('<%q>(.*)</%q>',sNode)) do
    table.insert(tValues,sText)
  end
  return tValues
end

for _,v in pairs(find 'item') do
  print(v)
end

This code would print all of the text inside of each <item>. You could use this function recursively on these <item>s to individually get the titles and other information in each <item>.
Nixsy #4
Posted 30 August 2012 - 12:26 AM
I think I understand But how would I get it to search for this string.

<title type="html"><![CDATA[Videos • Small server spawn update]]></title>
Nixsy #5
Posted 30 August 2012 - 05:27 PM
[edit] A very nice player on my server is helping with this :)/>/>

thanks for your help.