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

Broadcast an RSS Feed to Monitor

Started by Mastergalen, 30 May 2012 - 11:10 AM
Mastergalen #1
Posted 30 May 2012 - 01:10 PM
I was wondering if it is already possible to push an RSS feed to a Computer Craft monitor?

If yes, how would one do that?

Thanks in advance.
Kolpa #2
Posted 30 May 2012 - 02:55 PM
the problem is u have to read the xml feed and that is only possible with the string api and searching for the xml tags
what i did for reddit is i created a php page that reads out the json of the reddit api and returns the stuff that im interested in
so that i can read this page with lua and just split it at the points :)/>/>

see it in action at:Click me
cant_delete_account #3
Posted 30 May 2012 - 04:57 PM
the problem is u have to read the xml feed and that is only possible with the string api and searching for the xml tags
what i did for reddit is i created a php page that reads out the json of the reddit api and returns the stuff that im interested in
so that i can read this page with lua and just split it at the points :)/>/>

see it in action at:Click me
If I were to do this I would do it all it Lua because I'm quite bad at PHP. xD
Kolpa #4
Posted 05 June 2012 - 04:28 PM
well if u want to create an xml or json decoder fore something like this: json xml then have fun :)/>/> i like the php version more
kazagistar #5
Posted 05 June 2012 - 04:34 PM
Well, I guess you only need to be able to read a very small subset of XML. It could be done, but it would not be pretty.
Kolpa #6
Posted 05 June 2012 - 04:54 PM
well the problem is that there are more than 1 tag named the same at the reddit xml
like the <item> tag
kazagistar #7
Posted 05 June 2012 - 07:33 PM
Find the index of the first <item> tag, and replace everything before it with "parsed = {".

Find and replace each <item> with "{" and each </item> with "}".

Continue working your way into the structure throwing away what you dont want and reformatting what you do, until you get something like 'parsed = {{title="Yay",link="http://yay.com"}{title="Yay2",link="http://yay2.com")}'.

Then you use loadstring to load it in, and you can access it through tables. Easy! (kinda…)
Kolpa #8
Posted 08 June 2012 - 09:29 PM
Find the index of the first <item> tag, and replace everything before it with "parsed = {".

Find and replace each <item> with "{" and each </item> with "}".

Continue working your way into the structure throwing away what you dont want and reformatting what you do, until you get something like 'parsed = {{title="Yay",link="http://yay.com"}{title="Yay2",link="http://yay2.com")}'.

Then you use loadstring to load it in, and you can access it through tables. Easy! (kinda…)

didnt state that its impossible but well its way easier with an php script like this :


<?php
$sub = @$_GET['page'];
if (is_string($sub) == false) {
echo "please enter A Subreddit";
}
else
{
$str =file_get_contents("http://www.reddit.com/r/".$sub.".json");
$array = json_decode($str,true);
foreach($array['data']['children'] as $child) {
$text = $child['data']['title'];
$score = $child['data']['score'];
echo $text."<br> Score: ".$score."<br>";
}
}
?>